View Single Post
 
Old 02-12-2013, 02:23 AM
norgro norgro is offline Windows XP Office 2007
Novice
 
Join Date: Feb 2013
Location: Perh Australia
Posts: 12
norgro is on a distinguished road
Default Start of Document Code Problem

I am writing code to highlight "ance" in a Word document. In Braille, there is a contraction for "ance" (and other combinations of letters). My macro seems to work provinding the document does not start with "ance".

It would be appreciated if someone could tell me how to include the "if the document does not start with "ance" condition.

I am attaching the code.
Code:
Sub HighlightAnceIfNotStartOfWord() 
    Set oRng = ActiveDocument.Range 
     ' Search document for specified text and highlight text.
    With oRng.Find 
        .Text = "ance" 
         '
         ' .Highlight - colour - yellow if previous character if alphabetic character - otherwise turquoise.
        .Wrap = wdFindStop 'stops at the end of the document
        While .Execute 
             ' MsgBox (oRng.Characters.First.Previous)
            If (Asc(oRng.Characters.First.Previous) >= 65 And Asc(oRng.Characters.First.Previous) <= 90) _ 
            Or (Asc(oRng.Characters.First.Previous) >= 97 And Asc(oRng.Characters.First.Previous) <= 122) _ 
            Then 
                oRng.HighlightColorIndex = wdYellow 
            Else: oRng.HighlightColorIndex = wdTurquoise 
            End If 
        Wend 
    End With 
End Sub

Last edited by macropod; 02-12-2013 at 03:39 AM. Reason: Added code tags & formatting
Reply With Quote