View Single Post
 
Old 11-16-2018, 06:23 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,478
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

You could use something like:
Code:
Sub HiLightList()
Application.ScreenUpdating = False
Dim StrFnd As String, StrRep As String, i As Long
StrFnd = "if,then,from,to,all,first,between,first,last,of,and,or,print,find,swap," & _
  "check,print,count,when,require,do not,with,but,rather than,where,is not,as,in,an," & _
  "is,by,are,on,for,because,some,before,after,also,under,inside,around,into,next to," & _
  "often,let,delete,copy,find,calculate,check,print,until,was,were,behind,had been"
StrRep = "if,then,from,to,all,first,between,first,last,of,and,or,print,find,swap," & _
  "check,print,count,when,require,do not,with,but,rather than,where,is not,as,in,an," & _
  "is,by,are,on,for,because,some,before,after,also,under,inside,around,into,next to," & _
  "often,let,delete,copy,find,calculate,check,print,until,was,were,behind,had been"
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Replacement.Highlight = True
  .Format = True
  .Forward = True
  .MatchCase = False
  .MatchWholeWord = True
  .Wrap = wdFindContinue
  For i = 0 To UBound(Split(StrFnd, ","))
    .Text = Split(StrFnd, ",")(i)
    .Replacement.Text = "^l" & Split(StrRep, ",")(i)
    .Execute Replace:=wdReplaceAll
  Next
End With
Application.ScreenUpdating = True
End Sub
Note how the long lines are broken. The StrFnd and StrRep variables must have the same # of elements. Also note how the F/R code has been made more efficient by moving most of it outside the loop.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote