View Single Post
 
Old 05-26-2020, 07:43 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

What's wrong with a simple Find/Replace loop, rather than a nested one? Far quicker:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range, arrWords, i As Long
arrWords = Array("keyword1", "keyword2", "keyword3")
Options.DefaultHighlightColorIndex = wdYellow
Set Rng = Selection.Range
With Rng
  .Paste
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindStop
    .Replacement.Text = "^&"
    .Replacement.Highlight = True
    For i = 0 To UBound(arrWords)
      .Text = arrWords(i)
      .Execute Replace:=wdReplaceAll
    Next
  End With
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote