This is a variation on the multiple find/replace macro covered here: https://cybertext.wordpress.com/2015/03/03/word-macro-to-run-multiple-wildcard-find-and-replace-routines/. I suggest you read that post first (and test it) before attempting this one. This post assumes you can already do what’s in that earlier post.
Scenario
The scenario for this one is a little different — the author wanted to find various words in a document and highlight them for probable change. As there were MANY documents she had to process, she needed an easy way to find these words and highlight them. She didn’t want to change them at this stage. The words related to project names, company names, facility names, document number prefixes, etc. One project’s documents were to be the basis of a set of documents for another project in the same company, so one of the tasks was to ‘personalize’ the copies of the original project’s documents with the names used by the new project.
Solution
Although there may be several ways you can do this, I decided to stick with what I already knew. I figured that using a variation of the ReplaceTableWithList macro (as discussed here: https://cybertext.wordpress.com/2015/03/03/word-macro-to-run-multiple-wildcard-find-and-replace-routines/) and a new table called by that macro variation should solve it. And it did.
Step 1: Create your find/replace table
- Start a new Word document, and create a two-column table in it.
- In the left column, type in the words/phrases you want to find, each on a different row.
- In the right column, type 1. (This means that the wildcard find/replace will replace what was found with itself — remember, you’re only trying to identify the words that *may* need changing at this point, not changing them.)
- Save the document to this folder, noting the name of the file as you’ll need that later:
C:Users<your_username>AppDataRoamingMicrosoftWordSTARTUP.
Step 2: Set up the macro to work with the table
Add the macro below to an existing document, or better, an existing template, or even better, a central macros template that loads whenever you open Word.
Once you’ve added it, change the line that starts with sFname and has the file path — that path points to MY file on MY computer. You need to change it to YOUR file name and YOUR file path.
NOTE: Copy all the code below to the clipboard — it goes off the page, so don’t type it out as you’ll miss some of it or could make a typo.
Sub ReplaceFromTableListName() ' from Doug Robbins, Word MVP, Microsoft forums, Feb 2015, based on another macro written by Graham Mayor, Aug 2010 Dim oChanges As Document, oDoc As Document Dim oTable As Table Dim oRng As Range Dim rFindText As Range, rReplacement As Range Dim i As Long Dim sFname As String 'Change the path in the line below to reflect the name and path of the table document sFname = "C:UsersrhondaAppDataRoamingMicrosoftWordSTARTUPfind_and_replace_routines_names_macro.docx" Set oDoc = ActiveDocument Set oChanges = Documents.Open(FileName:=sFname, Visible:=False) Set oTable = oChanges.Tables(1) ' Make sure highlight is set to the colour you want, e.g. wdYellow, wdBrightGreen, wdPink, wdTurquoise Options.DefaultHighlightColorIndex = wdTurquoise For i = 1 To oTable.Rows.Count Set oRng = oDoc.Range Set rFindText = oTable.Cell(i, 1).Range rFindText.End = rFindText.End - 1 Set rReplacement = oTable.Cell(i, 2).Range rReplacement.End = rReplacement.End - 1 Selection.HomeKey wdStory With oRng.Find .ClearFormatting .Replacement.ClearFormatting .MatchWildcards = True .Text = rFindText.Text .Replacement.Text = rReplacement.Text .Replacement.Highlight = True .Forward = True .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With Next i oChanges.Close wdDoNotSaveChanges End Sub
Step 3: Test that it works
After setting up the ReplaceFromTableListName macro (above), run it on a test document — copy an existing document and test on the copy to make sure you don’t mess up anything.
NOTES:
- If you get an error message, check that you have the correct file name and path in the macro, AND check that your Word document containing the table that’s called by the macro has no empty rows.
- If none of the words in your table get highlighted in your document on the first pass, select a highlight colour from the Home tab as though you were going to highlight manually, then run the macro again.
- If some words are missed, check the table containing them — if a word has an initial capital in the table, but not in the document you are searching (e.g. in a URL), then the macro won’t highlight it. For words that could be capitalized in various ways, either add new lines for each variation, OR search for the part of the word you know won’t be capitalized (e.g. if you were searching for ‘Amazon’, then change the search term in the first column to ‘mazon’ to pick up the word whether it has an initial cap or not).
- Some areas of your document won’t get highlighted, even if they contain the words you’re looking for — e.g. headers and footers, text boxes. You’ll have to check for these manually.
My author was VERY happy — she had something that only took a few seconds to run and highlighted all the various words she needed to look for.
[Links last checked November 2015]
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 cant 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.
Find and replace multiple words at the same time in Word with VBA code
Easily find and replace multiple words at the same time in Word with an amazing feature
Find and replace multiple words at the same time in Word with VBA code
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.
Easily find and replace multiple words at the same time in Word with an amazing feature
The Batch Find and Replace feature of Kutools for Word can help to easily find and replace different texts in a document or across multiple documents at the same time.
Before apply this feature, please take minutes to download and install it firstly.
1. Launch the Microsoft Word application, click Kutools Plus > Batch Find and Replace.
2. In the Batch Find and Replace window, please configure as follows.
- 2.1 click the
button > Add File or Add Folder to add one or more documents in which you will find and replace multiple words.
- 2.2 Click the Add row button to insert the find and replace fields. If you want to find and replace three different texts at the same time, please create three rows.
- 2.3 In each row, enter the existing words you will replace with a new one in the Find column, and then enter the new words into the Replace column.
- 2.4 Specify the Search Type for each row.
- 2.5 In the Find in column, choose where to apply the find and replace. It includes Main document, Header and Footer in this section. You can choose one of them, two of them or all of them based on your needs.
- 2.6. Click the Replace button to start the operation. See screenshot:
Then the specific words are replaced in selected documents at the same time.
Tip: You can highlight the result with background color by specifying certain color in the Highlight column for a row.
If you want to have a free trial (60-day) of this utility, please click to download it, and then go to apply the operation according above steps.
Recommended Word Productivity Tools
Kutools For Word — More Than 100 Advanced Features For Word, Save Your 50% Time
- Complicated and repeated operations can be done one-time processing in seconds.
- Insert multiple images across folders into Word document at once.
- Merge and combine multiple Word files across folders into one with your desired order.
- Split the current document into separate documents according to heading, 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…
Read More Download Now Purchase
- 17 Comments
- Login
-
Sort by Newest
- Best
- Popular
- Newest
- Oldest
or post as a guest, but your post won’t be published automatically. Post
Loading comment… The comment will be refreshed after 00:00.
-
To post as a guest, your comment is unpublished.
excel guy · 3 months ago
Thanks for the project, Could you make it the way we can also replace letters in words. For example if i want to change Dollar as DoLLar it does not function.
- Reply
-
To post as a guest, your comment is unpublished.
Vern · 8 months ago
In the first instruction (Find And Replace Multiple Words At The Same Time In Word With VBA Code), it does not find instances where the word to be replaced falls in the middle of a word (For example, .com following a website name). Can this be modified to do so?
- Reply
-
To post as a guest, your comment is unpublished.
AJs · 8 months ago
What if I’m trying to replace commas?
- Reply
-
To post as a guest, your comment is unpublished.
crystal · 8 months ago
The VBA code can’t help to replace commas. You can apply Kutools to achieve.
- Reply
-
To post as a guest, your comment is unpublished.
Ajs · 8 months ago
After hitting Replace it just goes to Preview and doesn’t do anything further.
- Reply
-
To post as a guest, your comment is unpublished.
crystal · 8 months ago
Hi Ajs,
All required words have been successfully replaced at once after hitting the Replace button. It goes to the Preview tab to help you know how many words have been successfully replaced. After that, close the dialog box.
- Reply
-
To post as a guest, your comment is unpublished.
Walter Mendes · 1 years ago
Hi! First, congratulations for your work: this macro is very useful and interesting! I would like, neverthless, you help me with one thing. I am a proofreader and would like the replacements would highlithed in green or red color. How can I do this? Is there a code line I could use?
- Reply
-
To post as a guest, your comment is unpublished.
crystal · 1 years ago
Hi,
The Batch Find and Replace feature of Kutools for Word can perfectly solve your problem, you can have a try.
- Reply
-
To post as a guest, your comment is unpublished.
JM · 1 years ago
Hi how can this macro be revised to take more key words? I have about 170 words that I wold like to find and replace
- Reply
-
To post as a guest, your comment is unpublished.
crystal · 1 years ago
Hi JM,
After running the code, a Kutools for Excel dialog box will pop up, please enter the keywords you will find and separate them with commas.- Reply
-
To post as a guest, your comment is unpublished.
Ranjit Jagtap · 1 years ago
How to find and select multiple words at the same time
- Reply
-
To post as a guest, your comment is unpublished.
crystal · 1 years ago
Hi,
After running the code, a Kutools for Excel dialog box will pop up, please enter the keywords you will find and separate them with commas.- Reply
-
To post as a guest, your comment is unpublished.
Shailesh Pateliya · 2 years ago
Hi, This works well with English Words. Now I am doing a document where I translate English to Gujarati. So, when I apply this, (Find English Words) and (Replace with Gujarati words), it does change but it appears like «???». Doesn’t show the Gujarati word but just question marks? Any further help? Please.
- Reply
-
To post as a guest, your comment is unpublished.
Kirill · 9 months ago
Hello Shailesh, facing the same issue. Did you find a solution to it. Am also trying to figure out how to change from Chinese to English.
- Reply
-
To post as a guest, your comment is unpublished.
Adam · 2 years ago
Any way to make this case sensitive?
- Reply
-
To post as a guest, your comment is unpublished.
rishabh jain · 2 years ago
will this work in office Excel 365
- Reply
-
To post as a guest, your comment is unpublished.
jaka1 · 2 years ago
Toto jsem hledal, jen potřebuji pro hledaný text přidat nějaké formátování. Jak toho dosáhnu?
- Reply
Suppose I have a document with The quick brown fox jumps over the lazy dog
in it.
I want to find (and preferably replace) all instances of some words in a list, e.g. the
, fox
, dog
. The end result should match like so:
The quick brown fox jumps over the lazy dog
How can I do this with a single search, rather than searching each word separately?
Normally I would do something like ([Tt]he|fox|dog)
as a regular expression, but it seems Word doesn’t support the |
pipe operator.
I want solutions that are native to Microsoft Word, no add-ins or external programs please.
asked May 27, 2022 at 19:30
3
You need a macro do search for multiple words — such a capability is not part of Native Word.
The macro below can do this for you and search through your document.
Please see:
Macro to find multiple words
Sub HiLightList()
Application.ScreenUpdating = False
Dim StrFnd As String, Rng As Range, i As Long
StrFnd = "dog,cat,pig,horse,man"
For i = 0 To UBound(Split(StrFnd, ","))
Set Rng = ActiveDocument.Range
With Rng.Find
.ClearFormatting
.Text = Split(StrFnd, ",")(i)
.Replacement.ClearFormatting
.Replacement.Highlight = True
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = True
.Execute Replace:=wdReplaceAll
End With
Next
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
answered May 27, 2022 at 21:18
JohnJohn
43.6k3 gold badges31 silver badges53 bronze badges
You will need to use a VBA macro for that.
The following macro was found in the article
Macro trick: How to highlight multiple search strings in a Word document.
It searches and highlights the strings «very», «just», «of course».
The article further explains each command in the macro.
Sub HighlightWords()
Dim Word As Range
Dim WordCollection(2) As String
Dim Words As Variant
'Define list.
'If you add or delete, change value above in Dim statement.
WordCollection(0) = "very"
WordCollection(1) = "just"
WordCollection(2) = "of course"
'Set highlight color.
Options.DefaultHighlightColorIndex = wdYellow
'Clear existing formatting and settings in Find feature.
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
'Set highlight to replace setting.
Selection.Find.Replacement.Highlight = True
'Cycle through document and find words in collection.
'Highlight words when found.
For Each Word In ActiveDocument.Words
For Each Words In WordCollection
With Selection.Find
.Text = Words
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
Next
End Sub
Learn about macros in the Word Help and also the article
guide to installing macros.
Note that to use macros, the document must be of type .docm
and not
.docx
.
answered May 27, 2022 at 20:15
harrymcharrymc
439k30 gold badges506 silver badges885 bronze badges
Asked
4 years, 10 months ago
Viewed
203 times
In a word document i need to find all the words that start with a «<» and end with «keyword>». For example, , and so on…
I’ve found a standard regex for that, but since wildcards are not the same as regex, does anyone know an equivalent?
Thanx
- ms-word
- wildcard
asked Jun 11, 2018 at 17:31
OB-1OB-1
213 bronze badges
4
-
For best results include a sample of your data and your desired output.
Jun 11, 2018 at 17:32
-
Removed the
regex
tag asword
as far as I know does not support those.Jun 11, 2018 at 17:40
-
This question is about Microsoft Word. As the description of the [word] tag says, “questions on the general usage of Microsoft Word are off-topic for Stack Overflow and should be asked on Super User instead.”
Jun 11, 2018 at 17:43
-
@RoryO’Kane No, the information for the WORD tag does not say that — it says something completely different. The Word tag is for questions concerning the term «word». MS-Word is the correct tag for Microsoft Word.
Jun 12, 2018 at 12:18
Load 3 more related questions
Show fewer related questions
- The Overflow Blog
- Featured on Meta
Hot Network Questions
-
Reference request for condensed math
-
Problem with lstinline in the caption of lstlisting environment
-
Working out maximum current on connectors
-
How did Luke get back to Echo Base after crashing?
-
If a change of basis preserves the Lie bracket, why is the automorphism group of a Lie algebra not the entire general linear group?
-
How can any light get past a polarizer?
-
PC to phone file transfer speed
-
Does Ohm’s law always apply at any instantaneous point in time?
-
How to perform usability studies on complex software
-
M1 MacBook Air Base Model — How Much SSD Free Space exists on my 256 storage Mac?
-
Did Hitler say that «private enterprise cannot be maintained in a democracy»?
-
Only Connect — all at once!
-
If I can’t provide GPL source because a supplier did not provide it, am I at fault?
-
How to. automate nutrition calculation
-
Where did Christian monasteries originate from?
-
Help with understanding this «quote»
-
Distribution of the Normal Force
-
How would a future humanity «terraform» the moon?
-
Can ultra-low-frequency photon rockets be «safe»?
-
Etiquette (and common sense) rules for MTB cyclists
-
What additional inputs are required to convert dBFS to dB SPL?
-
Why does my company keep putting me under the same manager?
-
Do I know all the abilities of a Dominated creature?
-
Odds «ratio» in logistic regression?
more hot questions
Question feed
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Powerful substitute for Word’s Find / Replace dialogue and Navigation pane. Search Word documents for multiple words and phrases using standard text search or regular expressions, replace all or individual occurrences, change formatting of found text, review each occurrence with its context before making a change.
This tool is part of TransTools+
Multiple Find & Replace tool makes it extremely easy to find and replace text in Word documents using lists of search expressions. With its help, you will be able to find multiple words or phrases using standard text search or regular expressions, decide which occurrences need changing, and then replace them and/or format them as required.
Finding all occurrences of search expressions in a document with Multiple Find & Replace tool
Features
- Search a Word document for multiple words or phrases defined in reusable search expression lists.
- Use Microsoft Word’s Find & Replace syntax for simple searches, or use the powerful .NET regular expressions to perform complex searches and replacements.
- Automatically replace all occurrences of words / phrases defined in your list by using Replace All button.
- Confirm each replacement before it is made by using Find / Replace buttons.
- Display a list of all occurrences of words / phrases defined in your list using Find All button, and then see each occurrence in document context and preview how the text will appear after the replacement is made.
- Decide which found occurrences of words / phrases need to be processed, and use Replace Selected button to replace selected occurrences or Format Selected button to apply font formatting or highlight color to these occurrences.
- Search for text that has specific font formatting (including Bold, Italic, Underline style, Font Color, Font Size, Subscript and Superscript, Strikethrough and Double Strikethrough, All Caps and Small Caps).
- Modify the replacement text of specific occurrences of words / phrases based on context.
Multiple Find & Replace in action: screenshots
This tool is part of TransTools+, suite of productivity tools for Microsoft Office designed for translators, editors, content creators and DTP specialists.
30-day fully-functional trial. No banking details are required.
Quality assurance (QA) tools
TransTools+
- Highlighting Tool – simplify editing work: apply color highlighting, clear color highlighting, or find color highlighting
TransTools:
- Multiple Replace – replace several words or phrases simultaneously across a document or selection
- Correctomatic – correct words and phrases according to multiple correction lists
- Find Multiple Text – find words and phrases defined in your search-replace list for manual correction
Batch tools
TransTools+
- Document Processing Tool – perform various actions on multiple Word documents (DOCX, DOC, RTF format), using one or several different TransTools+ commands one after the other.
Any questions or comments?
Write us a message