Question Locked

Macro for selecting multiple words simultaneously in Word

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hello all,

Complete newbie here... very little coding/creating macro experience.

I've spent hours looking for a way to simultaneously find multiple words in a single Word document and have them converted to bold text, but am having no luck.

The Word document in question has a bibliography with hundreds of references with authors listed. I have a separate file with a list of ~300 authors' names I would like to highlight in the original document. Should be possible, no?

Does anyone have any pointers? (I hope this is posted with the right tags)

Many thanks in advance,
David

6 replies

by kees_b edited

In fact, there are 2 kinds of simultaneous in your question: (1) all occurrences of 1 name, and (2) all occurrences of all names,

It seems quite possible to write this as a loop over the 300 names in the list. Then for each name, loop over all occurrences in the text.

I'm afraid you need to either do it manually, or find someone to code it for you. They might want to be paid, if you don't have friends of family members to do it.

by dpennisi

Hi kees_b and alishaalishakhan340,

Thanks for the responses. I'll try the macros suggested, otherwise it may require getting someone to write the code!

Regards,
David

by hassaansiddiqui200215 edited

To simultaneously find and convert multiple words to bold text in a Word document, you can use a simple VBA macro. Here's a basic solution:

Open your Word document.
Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
Go to Insert > Module to create a new module.
Copy and paste the following VBA code into the module:

Sub HighlightWords()
Dim word As Range
Dim wordList As Variant
Dim i As Long

' List of words to be highlighted
wordList = Array("word1", "word2", "word3") ' Add your list of authors' names here

For i = LBound(wordList) To UBound(wordList)
With ActiveDocument.Content.Find
.Text = wordList(i)
.Forward = True
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

Do While .Execute
If .Found Then
Set word = Selection.Range
word.Font.Bold = True
End If
Loop
End With
Next i
End Sub

Customize the wordList array with the list of authors' names you want to highlight.
Close the VBA editor and return to your Word document.
Press Alt + F8, select the "HighlightWords" macro, and click "Run" to execute the macro.
This macro will search for each word in your list and convert them to bold wherever they are found in the document.

Hope this helps!

by dpennisi

Hi hassaansiddiqui200215,

Thanks for that - I'll try this as well as see how it goes.

Kind regards,
DP

by cassharper030 edited

While creating a macro is possible, there's a simpler way! Here's how you can find and highlight those authors' names:

Open both your document and the list of authors.
In your document, click the "Find" button (or press Ctrl+H).
Copy and paste an author's name from your list into the "Find what" box.
Click "Format" and choose "Font". Make sure "Bold" is selected.
Click "Replace All" (important!). Word will find and bold all instances of that author's name in your document.
Repeat steps 3-5 for each author name on your list.

by ethan547423

Hey David, totally possible and a smart idea for managing a big bibliography. You could definitely use a simple VBA macro for that loop through your list of names and apply bold formatting wherever there's a match. I’ve done something similar for keyword highlighting. Let me know if you want help putting the macro together.

This discussion is closed to new replies.