Log in  \/ 
x
or
 Use Facebook account  Use Google account  Use Microsoft account  Use LinkedIn account
x
x
Register  \/ 
x

or
 Use Facebook account  Use Google account  Use Microsoft account  Use LinkedIn account

How to search and replace across multiple files in word?

If you have several dozen word files which contain the same content (such as Header, footer, some special words or number), and you need to replace the same content across those documents in Word. How would it be easier for you to get it done quickly? Certainly, you can open those files one by one to replace the same content, but it will be time-consuming and troublesome. This tutorial will show you a tricky way to replace same content within multiple documents in Word at once.

Kutools for Word: Add 100 New Advanced Features to Word 2003/2007/2010/2013/2016.
Office Tab: Enable Tabbed Editing and Browsing in Office, Just Like Chrome, Firefox, IE 8/9/10.
Classic Menu for Office: Bring Old Look of Office 2003 Back to Office 2007, 2010, 2013 and 2016.

Using a VBA for searching and replacing same content across multiple documents at one time in Word:

Hot
Amazing! Using Tabs in Word like Firefox, Chrome, Internet Explore 10!

Learn more Free download

Step 1: Press “Alt-F11” to open the Microsoft Visual Basic for Application window;

Step 2: Click Module on the Insert tab, copy and paste the following VBA code into the Module window;

Step 3: Then click Run doc-remove-numeric-characters-1 button to apply the VBA.

VBA: searching and replacing same content across multiple documents at one time

Sub CommandButton1_Click()
Dim MyDialog As FileDialog, GetStr(1 To 100) As String '100 files is the maximum applying this code
On Error Resume Next
Set MyDialog = Application.FileDialog(msoFileDialogFilePicker)
With MyDialog
.Filters.Clear
.Filters.Add "All WORD File ", "*.docx", 1
.AllowMultiSelect = True
i = 1
If .Show = -1 Then
For Each stiSelectedItem In .SelectedItems
GetStr(i) = stiSelectedItem
i = i + 1
Next
i = i - 1
End If
Application.ScreenUpdating = False
For j = 1 To i Step 1
Set Doc = Documents.Open(FileName:=GetStr(j), Visible:=True)
Windows(GetStr(j)).Activate
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "search" 'Find What
.Replacement.Text = "find" 'Replace With
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Application.Run macroname:="NEWMACROS"
ActiveDocument.Save
ActiveWindow.Close
Next
Application.ScreenUpdating = True
End With
MsgBox "operation end, please view", vbInformation
End Sub

Note: you can change the Text = "search”, Replacement.Text = "find” to specify the content to be searched and the content to be applied for replacement.


arrow blue right bubble Kutools for Word

More than 100 Advanced Functions for Word 2003, 2007, 2010, 2013 and 2016

shot-kutools-700-225-kte

More Features  |  Free Download  |  Only $39.00 for hundreds of functions

Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    CC · 1 months ago
    Merlin 4099, I am having trouble with the following portion of your code. I am new to VBA.:

    ' --------------- --------------- --------------- ----------
    ' Beginning Header Updates
    ' --------------- --------------- --------------- ----------
    Windows(GetStr(j)).Activate
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.Cle arFormatting

    If ActiveWindow.View.SplitSpecialwdPane None Then
    ActiveWindow.Panes(2).Close
    End If

    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
    ActivePane.View .Type = wdOutlineView Then

    Can anyone help me? I think I fixed most
  • To post as a guest, your comment is unpublished.
    CC · 1 months ago
    Merlin4099, I am having trouble with the following portion of your code:

    ' --------------- --------------- --------------- ----------
    ' Beginning Header Updates
    ' --------------- --------------- --------------- ----------
    Windows(GetStr(j)).Activate
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.Cle arFormatting

    If ActiveWindow.View.SplitSpecialwdPane None Then
    ActiveWindow.Panes(2).Close
    End If

    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
    ActivePane.View .Type = wdOutlineView Then

    Can you or anyone else help me?

    Thanks!
  • To post as a guest, your comment is unpublished.
    DaveW · 2 months ago
    Thanks so much for posting this, absolute lifesaver!

    I notice that there is a line "MatchWildcards = False", which implies that it's possible to use wildcards in the search text - is that possible and, if so, what's the protocol?

    Thanks again!
  • To post as a guest, your comment is unpublished.
    Paul Oz · 4 months ago
    Hi all,
    I am new to the whole VBA thing and I Love love love this code!
    I have 5000+ docs to review and if this works it will save heaps of time!
    I have the code above running however i can see that it does not cater for replacing text in footers, Only headers and the body of the doc.
    Can anyone assist in extending this to the entire document.
    P.S. not sure if this is relevant but the list of words that i need to replace is the same for headers, footers and the body...
    Any help would really be appreciated!
  • To post as a guest, your comment is unpublished.
    Terence · 6 months ago
    Out of interest what does the line: Application.Run macroname:="NEW MACROS" do?
    The rest of the code makes sense to me (used to VBA in Excel) but I can't figure out why you need to execute another piece of code here.
    Thanks for the great tool though.