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.
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:
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 button to apply the VBA.
VBA: searching and replacing same content across multiple documents at one time
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)
.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
Application.ScreenUpdating = False
For j = 1 To i Step 1
Set Doc = Documents.Open(FileName:=GetStr(j), Visible:=True)
.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
Application.ScreenUpdating = True
MsgBox "operation end, please view", vbInformation
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.
Kutools for Word
More than 100 Advanced Functions for Word 2003, 2007, 2010, 2013 and 2016
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.· 14 days agoHi there, is there a code for replacing with text that is multiple sentences, with bullet points and quotation marks in MS word using this code - which is fantastic !
To post as a guest, your comment is unpublished.· 2 months agohi, i want to replace a number but i guess the problem that it's not working is that the number is not written in english it's in Persian. I would be so thankfull if someone can help me with it.
To post as a guest, your comment is unpublished.· 2 months agosorry, i was wrong. the problem is that the number is in the header and it seems that the trick is not working in header. if i open one of the files and activate the header then run the module it works but just in that specific file ,even if i select all the files. thanks again.
To post as a guest, your comment is unpublished.· 2 months agoHi, I new to VBA. I am able to get the data updated for only single file. How to select multiple files when the VBA script opens up ? The question might be simple to few, but it will help. Since i need to update a string in 175+ plus word files. Appreciate your quick response. Thanks ...
To post as a guest, your comment is unpublished.· 3 months agoHi
this code is only editing 7 documents at a time... why?
To post as a guest, your comment is unpublished.· 4 months agoI really appreciated this post. Thank you. It allowed me to spend 10 minutes implementing something that saved several hours of work.
- ← Previous
- Next →