How to Find and Replace Multiple Items in Your Word Document

In today’s article, we would like to explain to you of how to find and replace multiple items in your Word document.

The built-in function in Word, “Find and Replace”, allows us to find and replace a word or a phrase at a time. This certainly cannot meet our need for batch processing.

As a matter of fact, we’ve extended the function to find multiple items in one time in one of our previous article. For more details, you can refer to this article: 2 Quick Ways to Find Multiple Items in One Word Document at the Same Time

The above link discussed how to find multiple items at the same time. And this article will also show you how to replace each item with a different new one respectively.Find and Replace Multiple Items in Your Word Document

Run Word VBA to Find and Replace Multiple Items

Macro is the only way left to do customized and batch processing tasks in Word. Just follow bellowing steps to accomplish your mission.

  1. First and foremost, open your target document.
  2. Then click “Developer” tab if it’s available in the Ribbon.
  3. And click “Visual Basic” next to open the VBA editor in Word. Or you can choose to press “Alt+ F11” instead.
  4. Next click “Normal” on the left column.
  5. And go to menu bar to click “Insert”.
  6. On its drop-down menu, choose “Module”.Click "Normal"->Click "Insert"->Click "Module"
  7. Then double click on the new module as to open it.
  8. Paste following codes on module:
Sub FindAndReplaceMultiItems()
  Dim strFindText As String
  Dim strReplaceText As String
  Dim nSplitItem As Long
   
  Application.ScreenUpdating = False

  ' Enter items to be replaces and new ones.
  strFindText = InputBox("Enter items to be found here,seperated by comma: ", "Items to be found")
  strReplaceText = InputBox("Enter new items here, seperated by comma: ", "New items")
  nSplitItem = UBound(Split(strFindText, ","))

  ' Find each item and replace it with new one respectively.
  For nSplitItem = 0 To nSplitItem
    With Selection
      .HomeKey Unit:=wdStory
      With Selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = Split(strFindText, ",")(nSplitItem)
        .Replacement.Text = Split(strReplaceText, ",")(nSplitItem)
        .Format = False
        .MatchWholeWord = False
      End With
    Selection.Find.Execute Replace:=wdReplaceAll
  End With
Next nSplitItem

  Application.ScreenUpdating = True

End Sub
  1. Press “F5” to run the macro.Paste Codes ->Click "Run"
  2. Now there will be the first input box. Enter items to be found and use comma to separate. Don’t enter a space after comma.
  3. Then click “OK” to proceed.
  4. In the second input box, enter new items and separate them with comma.
  5. Finally, click “OK”.Enter Items in Both Input Boxes and Click "OK"

In the Face of Data Loss

It’s hard to be cheerful in the face of a data disaster which might destroy valuable information. However, there is no need to be panic since you can obtain a Word repair utility by shelling out a small amount of money.

Author Introduction:

Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including excel corruption and pdf repair software products. For more information visit www.datanumen.com

Leave a Reply

Your email address will not be published. Required fields are marked *