View Single Post
 
Old 02-12-2013, 03:49 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit 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

Try the following:
Code:
Sub HighlightAnceIfNotStartOfWord()
' Search document for specified text and highlight text.
With ActiveDocument.Range
    With .Find
        .Text = "ance"
         ' .Highlight - colour - yellow if previous character if alphabetic character - otherwise turquoise.
        .Wrap = wdFindStop 'stops at the end of the document
        .Execute
    End With
    Do While .Find.Found
        If .Characters.First.Previous Like "[A-Za-z]" Then
            .HighlightColorIndex = wdYellow
        Else
            .HighlightColorIndex = wdTurquoise
        End If
        .Collapse wdCollapseEnd
        .Find.Execute
    Loop
End With
End Sub
PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote