Thank you Andrew and Macropod for taking the time to share your code, it is very much appreciated.
Macropod, I have just run DemoB and works perfectly if there are no cross reference fields within the document but appears to bug if there are cross reference fields.
Code:
.Start = .Words(2).Start
I have a second string (StrFndB) that should highlight digits before those words but not sure how to add that to your second code (DemoB).
Code:
Sub DemoB()
Application.ScreenUpdating = False
Dim StrFndA As String, StrFndB As String, i As Long, Rng As Range
StrFndA = "[Cc]lause,[Pp]aragraph,[Pp]art,[Ss]chedule" 'highlight numbers after these words
StrFndB = "[Mm]inute,[Hh]our,[Dd]ay,[Ww]eek,[Mm]onth,[Yy]ear,[Ww]orking,[Bb]usiness" 'highlight numbers before these words
For Each Rng In ActiveDocument.StoryRanges
With Rng
Select Case .StoryType
Case wdMainTextStory, wdFootnotesStory
For i = 0 To UBound(Split(StrFndA, ","))
With .Duplicate
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.text = Split(StrFndA, ",")(i) & "[s \^s]@[0-9.]{1,}"
End With
Do While .Find.Execute
.Start = .Words(2).Start
.HighlightColorIndex = wdTurquoise
.Collapse wdCollapseEnd
Loop
End With
Next
Case Else
End Select
End With
Next Rng
Application.ScreenUpdating = True
End Sub