View Single Post
 
Old 05-26-2020, 06:51 AM
alex100 alex100 is offline Windows 7 64bit Office 2016
Advanced Beginner
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default Highlight keywords in the pasted text

The script below is supposed to highlight certain keywords in the text that was just pasted. The problem is that it's only highlighting the first keyword in the array, without any results for the rest of the keywords.

What could be the problem, please?

Alex

Code:
Dim pasted_content As Word.range
Dim r As Long
Dim Keywords
    
Keywords = Array("keyword1", "keyword2", "keyword3")

Set pasted_content = Selection.range
pasted_content.Paste

For r = 0 To UBound(Keywords)
    With pasted_content.Find
        .Text = Keywords(r)
        .Format = True
        Do While .Execute(Forward:=True) = True
            pasted_content.HighlightColorIndex = wdYellow
        Loop
    End With
Next
Reply With Quote