View Single Post
 
Old 02-24-2014, 02:21 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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 code like:
Code:
Sub HighlightTargetsN()
Dim Rng As Range, i As Long, TargetList
TargetList = Array("MMN") ' put list of terms to find here
For i = 0 To UBound(TargetList)
  Set Rng = ActiveDocument.Range
  With Rng
    With .Find
      .Text = TargetList(i)
      .Format = True
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Forward = True
      .Wrap = wdFindStop
      .Execute
    End With
    Do While .Find.Found
      .HighlightColorIndex = wdBrightGreen
      With .Font
        .Bold = True
        .ColorIndex = wdRed
        .Underline = wdUnderlineThick
        .UnderlineColor = wdRed
        .Name = "TW Cen MT"
        .Size = 14
      End With
      If .Information(wdWithInTable) = True Then
        .Cells(1).Shading.BackgroundPatternColorIndex = wdYellow
      End If
      .Collapse wdCollapseEnd
      .Find.Execute
    Loop
  End With
Next
End Sub
Note: I've played around with the colouring so as to differentiate each component's actions. Also, it's not a good idea to give variables the same names as reserved words (e.g. range), as this can lead to strange errors.

For a different way of handling this, which uses the mailmerge functionality instead of post-processing via a macro, see: http://answers.microsoft.com/en-us/o...7-86553a7f8188
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote