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.
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.
- First and foremost, open your target document.
- Then click “Developer” tab if it’s available in the Ribbon.
- And click “Visual Basic” next to open the VBA editor in Word. Or you can choose to press “Alt+ F11” instead.
- Next click “Normal” on the left column.
- And go to menu bar to click “Insert”.
- On its drop-down menu, choose “Module”.
- Then double click on the new module as to open it.
- 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
- Press “F5” to run the macro.
- 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.
- Then click “OK” to proceed.
- In the second input box, enter new items and separate them with comma.
- Finally, 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