Thread: [Solved] Highlight parent word
View Single Post
 
Old 03-09-2013, 12:18 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,382
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

Hi norgro,

You can't select discontiguous ranges with a macro, so your Find/Replace would have to use something like:
Code:
Sub Demo()
With ActiveDocument.Content.Find
  .ClearFormatting
  .Text = Selection.Text
  With .Replacement
    .ClearFormatting
    .Text = "^&"
    .Highlight = True
  End With
  .Forward = True
  .Wrap = wdFindContinue
  .Format = True
  .MatchCase = False
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  .Execute Replace:=wdReplaceAll
End With
End Sub
The problem with any Find/Replace approach is that it changes your document's content. However, if you select the input expression, press Ctrl-F, right-arrow, Word will temporarily highlight all occurences of the term.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote