Log in
x
or
x
x
Register
x

or
0
0
0
s2smodern

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.
People in conversation:
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    3Cees · 10 days ago
    Thank you so much. You win the internet!

    This has saved me amending 360 documents.

    You're my favourite :)
  • To post as a guest, your comment is unpublished.
    WAK · 1 months ago
    worked like a charm for me. Thanks a billion!
  • To post as a guest, your comment is unpublished.
    CC · 3 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.
      blue_crayon · 1 months ago
      Was figuring out this issue myself, today.

      First, make sure you fix the line:

      Selection.Find.Replacement.Cle arFormatting

      To be:

      Selection.Find.Replacement.ClearFormatting

      Then, change the following line:

      If ActiveWindow.View.SplitSpecialwdPane None Then

      To look like this:

      If ActiveWindow.View.SplitSpecial <> wdPaneNone Then


      The code should look like this in the end:

      Windows(GetStr(j)).Activate
      Selection.Find.ClearFormatting
      Selection.Find.Replacement.ClearFormatting

      If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
      ActiveWindow.Panes(2).Close
      End If

      If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
      ActivePane.View.Type = wdOutlineView Then
      ActiveWindow.ActivePane.View.Type = wdPrintView
      End If
  • To post as a guest, your comment is unpublished.
    CC · 3 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 · 4 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!