View Single Post
 
Old 09-21-2023, 11:21 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
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

It may not be possible to do this in a single pass, without knowing what else is in the document, so I would suggest a sequential search e.g. as below. This should search the common story ranges in a document, but if not the coding gets more complicated to cover the less common ones, to which end I would suggest Document Batch Processes,
See also Replace using wildcards


Code:
Option Explicit

Sub Macro1()
Dim vFindText As Variant
Dim i As Long
Dim oStory As Range
    vFindText = Array("25.222", "25.2666", "25.223")
   
    For Each oStory In ActiveDocument.StoryRanges
        For i = 0 To UBound(vFindText)
            With oStory.Find
                .ClearFormatting
                .Replacement.ClearFormatting
                .MatchWildcards = True
                Do While .Execute(findText:=vFindText(i))
                    oStory.HighlightColorIndex = wdTurquoise
                    oStory.Collapse 0
                Loop
            End With
        Next i
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
                For i = 0 To UBound(vFindText)
                    With oStory.Find
                        .ClearFormatting
                        .Replacement.ClearFormatting
                        .MatchWildcards = True
                        Do While .Execute(findText:=vFindText(i))
                            oStory.HighlightColorIndex = wdTurquoise
                            oStory.Collapse 0
                        Loop
                    End With
                Next i
            Wend
        End If
    Next oStory
lbl_Exit:
    Set oStory = Nothing
    Exit Sub
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