How to find and replace multiple words at the same time in a Word document?
Word provides a Find and Replace function to find all instances of a word or phrase and replace them with a new word at the same time. But if you want to find and replace different words at the same time, this build-in function can’t help. In this article, we are talking about a VBA method to find and replace multiple different words at the same time in Word document.
Please do as follows to find and replace multiple word at the same time in a Word document.
1. Open the Word document you want to find and replace multiple words at the same time, then press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.
2. In the Microsoft Visual Basic for Applications window, click Insert > Module. Then copy below VBA code into the Module window.
VBA code: Find and replace multiple words at the same time in Word
Sub FindAndReplaceMultiItems() 'Update by ExtendOffice 2018/10/25 Dim xFind As String Dim xReplace As String Dim xFindArr, xReplaceArr Dim I As Long Application.ScreenUpdating = False xFind = InputBox("Enter items to be found here,seperated by comma: ", "Kutools for Word") xReplace = InputBox("Enter new items here, seperated by comma: ", "Kutools for Word") xFindArr = Split(xFind, ",") xReplaceArr = Split(xReplace, ",") If UBound(xFindArr) <> UBound(xReplaceArr) Then MsgBox "Find and replace characters must be equal.", vbInformation, "Kutools for Word" Exit Sub End If For I = 0 To UBound(xFindArr) Selection.HomeKey Unit:=wdStory With Selection.Find .ClearFormatting .Replacement.ClearFormatting .Text = xFindArr(I) .Replacement.Text = xReplaceArr(I) .Format = False .MatchWholeWord = False End With Selection.Find.Execute Replace:=wdReplaceAll Next Application.ScreenUpdating = True End Sub
3. Press the F5 key to run the code.
4. In the first Kutools for Word dialog box, enter the multiple words you will find and replace into the textbox, and separate them with comma, then click the OK button. See screenshot:
5. In the second Kutools for Word dialog box, enter the new words you will replace with (these words also need to be separated by commas), and then click the OK button.
Note: In this case, all “KTE” in this document will be replaced with “New”, and “KTO” and “KTW” will be replaced with “Test” and “Finish”. Please change them to your needs.
Recommended Productivity Tools
- Complicated and repeated operations can be done a one-time processing in seconds.
- Insert multiple images across folders into Word document at once.
- Merge and combine multiple Word files across folders in to one with your desired order.
- Split the current document into separate documents according to heading 1, section break or other criteria.
- Convert files between Doc and Docx, Docx and PDF, collection of tools for common conversions and selection, and so on...