Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in


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.

Find and replace texts across multiple word documents at the same time with VBA code

Combine/merge multiple documents into one easily:

The Merge Documents utility of Kutools for Word can help you to combine multiple documents into one quickly. You just need to:

  • Select the documents you will combine into one;
  • Specify the break between each combined document;
  • Start merging. See screenshot:

Kutools for Word: with more than 100 handy Word add-ins, free to try with no limitation in 30 days. Download and free trial Now!

Kutools for Word: Add 100 New Advanced Features to Word 2003 / 2007 / 2010 / 2013 / 2016 / 2019.
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, 2016 and 2019.

Find and replace texts across multiple word documents at the same time with VBA code

1. Press Alt + F11 to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, click InsertModule, then copy  the following VBA code into the Module window.

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

Sub CommandButton1_Click()
'Updated by Extendoffice 20180625
Dim xFileDialog As FileDialog, GetStr(1 To 100) As String '100 files is the maximum applying this code
Dim xFindStr As String
Dim xReplaceStr As String
Dim xDoc As Document
On Error Resume Next
Set xFileDialog = Application.FileDialog(msoFileDialogFilePicker)
With xFileDialog
    .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
        i = i - 1
    End If
    Application.ScreenUpdating = False
    xFindStr = InputBox("Find what:", "Kutools for Word", xFindStr)
    xReplaceStr = InputBox("Replace with:", "Kutools for Word", xReplaceStr)
    For j = 1 To i Step 1
        Set xDoc = Documents.Open(FileName:=GetStr(j), Visible:=True)
        With Selection.Find
            .Text = xFindStr  'Find What
            .Replacement.Text = xReplaceStr  '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"
    Application.ScreenUpdating = True
End With
MsgBox "Operation end, please view", vbInformation
End Sub

3. Press the F5 key to run the code.

4. In the opening Browse window, please find and select the documents you will find and replace text inside, and then click the OK button. See screenshot:

5. In the first Kutools for Word dialog box, enter the text you will find across documents into the Find what box, and then click the OK button.

6. In the second Kutools for Word dialog box, enter the text you will replace with, and click the OK button.

8. Click the OK button in the next Microsoft Word dialog box to finish the find and replace.

In this case, all words "Word" in selected documents are replaced with "Excel" at the same time.

Office Tab - Tabbed Browsing, Editing, and Managing of multiple Documents in Word:

Office Tab brings the tabbed interface as seen in web browsers such as Google Chrome, Internet Explorer new versions and Firefox to Microsoft Word. It will be a time-saving tool and irreplaceble in your work. See below demo:

Click for free trial of Office Tab!

Kutools for Word

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


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.
    Nick · 2 years ago
    I am trying to add an entire section to a document that has three lines, bolding, and bullet points. Is there a way to keep that formatting when running the macro?
  • To post as a guest, your comment is unpublished.
    Tali1953 · 2 years ago
    To Merlin4099
    You have just saved my life (... time...) with you code !
    THANK YOU !!!
  • To post as a guest, your comment is unpublished.
    Jelena · 3 years ago
    Is it possible to change code and search and replace photo in multiply files?
  • To post as a guest, your comment is unpublished.
    fatma · 3 years ago
    this was sooo helpful, thank you very much! I have just changed the contents in 90 word files. This is amazing! Just one more tip: at the beginning close all open word documents but one of your file to be change.
  • To post as a guest, your comment is unpublished.
    Exis,LLC · 3 years ago
    You can use a program such as [url]www.officefindreplace.com[/url] to perform the same operation on multiple documents, or multiple operations on the same document. [url]www.officefindreplace.com[/url]