How to bold all instances of the same word in a Word document?

To bold all occurrences of a specific word in a Word document, you can use the following VBA code:

  1. Press ALT + F11 to open the Microsoft Visual Basic for Applications window.
  2. Click Insert > Module, then copy and paste the following code into the empty module:

Sub BoldAllOccurrences()
Dim targetWord As String
targetWord = InputBox(“Enter the word you want to bold:”, “Bold All Occurrences”)

If Trim(targetWord) = “” Then
MsgBox “Please enter a valid word.”, vbExclamation, “Bold All Occurrences”
Exit Sub
End If

With ActiveDocument.Content.Find
.ClearFormatting
.Text = targetWord
.Replacement.ClearFormatting
.Replacement.Font.Bold = True
.Replacement.Text = “^&”
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

Do While .Execute(Replace:=wdReplaceOne)
‘ Continue finding and replacing until no more occurrences are found.
Loop
End With
End Sub

  1. After inserting the code, press F5 to run the code. A dialog box will appear prompting you to enter the word you want to bold, as shown below:
How to bold all instances of the same word in a Word document

How to bold all instances of the same word in a Word document

  1. Click OK, and all occurrences of the specific word will be bolded throughout the entire document.

Make sure to save your document before running VBA code to avoid unintended data loss.

Gotkey.net
Logo
Compare items
  • Total (0)
Compare
0
Shopping cart