View Single Post
 
Old 03-14-2024, 07:42 AM
NotOriginal NotOriginal is offline Windows 11 Office 2021
Novice
 
Join Date: Mar 2024
Posts: 1
NotOriginal is on a distinguished road
Question Bold Term Macro that DOES NOT bold terms with Quotation Marks

Long time lurker, first time poster. I have a macro for MS Word that searches/bolds 115 terms, however, I need the macro to avoid bolding terms that are in quotations. For example, I have the word closing in bold, but if it is displayed as "closing" then I want that term to be ignored. Is there a way to do this?

A sample of my code is below:

Sub BoldPolicyWords()

Dim wordsToBold(1 To 3) As String
wordsToBold(1) = "word 1"
wordsToBold(2) = "word 2"
wordsToBold(3) = "word 3"


For i = 1 To 3

With Selection.Find
.Text = wordsToBold(i)
.Replacement.Text = "" ' Replace with empty string (optional)
.Replacement.Font.Bold = True
.Forward = True
.Wrap = wdFindContinue
.MatchWholeWord = True
End With

Selection.Find.Execute Replace:=wdReplaceAll
Next i

End Sub
Reply With Quote