View Single Post
 
Old 11-10-2021, 05:58 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Based on your example, the following modification to Andrew's code should work
Code:
Sub Macro2()
Dim aRng As Range
    Set aRng = ActiveDocument.Range
    With aRng.Find
        .ClearFormatting
        .Text = "Section"
        .MatchWildcards = True
        Do While .Execute  ' Loop until Word can no longer find the search string
            aRng.MoveEnd wdWord, 2
            aRng.MoveEndWhile "0123456789."
            aRng.Start = aRng.Words(2).Start
            If aRng.Fields.Count > 0 Then    'there is a field
                If aRng.Fields(1).Type = 3 Then aRng.Font.ColorIndex = wdBlue   'wdFieldRef=3
            Else
                aRng.Font.ColorIndex = wdRed
                ActiveDocument.Comments.Add Range:=aRng, Text:="Missing cross-reference field code"
            End If
            aRng.Collapse 0      'wdCollapseEnd
        Loop
    End With
    Set aRng = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote