Highlight multiple words

I want to highlight treaty and custom in a word file in one time. Is this possible with Find and Replace?

Thanks in advance

Answer
Answer

The short answer is 'no' - at least not in a single pass; but it is easy enough to do with a macro

Sub Highlight()
Dim vFindText As Variant
Dim oRng As Range
Dim i As Long
    vFindText = Array("custom", "treaty")
    For i = 0 To UBound(vFindText)
        Set oRng = ActiveDocument.Range
        With oRng.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            Do While .Execute(FindText:=vFindText(i), _
                              MatchWholeWord:=True, _
                              Forward:=True, _
                              Wrap:=wdFindStop) = True
                oRng.HighlightColorIndex = wdYellow
                oRng.Collapse wdCollapseEnd
            Loop
        End With
    Next
lbl_Exit:
    Exit Sub
End Sub

http://www.gmayor.com/installing_macro.htm   

Graham Mayor (Microsoft Word MVP 2002-2019)
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated April 14, 2025 Views 556 Applies to: