![]() |
|
|
|
#1
|
||||
|
||||
|
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 |
|
#2
|
|||
|
|||
|
Hi Graham,
Thanks for the help! We're almost there! Unfortunately, it is picking up more than "Section n". I ran the code on a new file and attached it (test_file_gmayor.docm). For example, we got a hit on "Section in-". If you have a moment, could you take a look at page 4, please? There, you'll see where we're getting more than Section n. Any ideas?Sorry for the trouble, but I really do appreciate the assistance! Thanks, Roy |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Field Code: Page number for current StyleRef | Cosmo | Word | 4 | 11-15-2020 03:54 PM |
| Word 2016: How do I change a REF field code to display a reference to a Roman number as Arabic | Peggy Sue | Word | 1 | 08-15-2017 09:50 PM |
VBA Code to search for field codes with certain text before the Field code and to change style
|
welcometocandyland | Word VBA | 4 | 02-08-2017 06:53 PM |
Is there a way programmatically to determine the footnote number style, if other than arabic numbers
|
gn4619 | Word VBA | 2 | 11-23-2015 11:00 PM |
Version number from document filename via field code
|
palanski | Word | 3 | 10-15-2014 01:54 PM |