View Single Post
 
Old 11-27-2017, 04:15 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,363
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

The code you posted assumes Word's highlighting has already been set to whatever highlights you want to use; if it's set to 'no highlighting, that's what you'll get. Try:
Code:
Sub FindAndHighlight()
Application.ScreenUpdating = False
Options.DefaultHighlightColorIndex = wdBrightGreen
Dim StrFnd As String, i As Long, StrRpt As String
StrFnd = "tasks,architecture,java"
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Replacement.Highlight = True
  .Forward = True
  .Wrap = wdFindContinue
  .Format = True
  .MatchCase = False
  .MatchWholeWord = True
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = True
  For i = 0 To UBound(Split(StrFnd, ","))
    .Text = Split(StrFnd, ",")(i)
    .Replacement.Text = "^&"
    .Execute Replace:=wdReplaceAll
    If .Found = True Then StrRpt = StrRpt & vbCr & Split(StrFnd, ",")(i)
  Next
End With
If StrRpt = "" Then
  MsgBox "None of the terms were found.", vbOKOnly
Else
  MsgBox "The following terms were found:" & StrRpt, vbInformation
End If
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote