Thread: [Solved] Highlight parent word
View Single Post
 
Old 03-09-2013, 01:58 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,

The mere fact that a string can be found in various words doesn't make one the parent of the other. For what you're after, try:
Code:
Sub Demo()
With ActiveDocument.Content
  With .Find
    .ClearFormatting
    .Text = Selection.Text
    With .Replacement
      .ClearFormatting
      .Text = ""
    End With
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  While .Find.Found = True
    .Expand wdWord
    If Right(.Text, 1) = " " Then
      .End = .End - 1
    End If
    .HighlightColorIndex = wdBrightGreen
    .Collapse wdCollapseEnd
    .Find.Execute
  Wend
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote