View Single Post
 
Old 04-20-2018, 04:10 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Perhaps:
Code:
Private Function testingRegEx()
    Dim re As RegExp
    Dim txt As String
    Dim allmatches As MatchCollection, m As Match
    
    Set re = New RegExp
    
    re.Pattern = "(Lorem)"
    re.IgnoreCase = True
    re.Global = True
    
    txt = ActiveDocument.Range.Text
    
    If re.TEST(txt) Then
        'get all matches
        Set allmatches = re.Execute(txt)
        'look at each match and hilight corresponding range
        For Each m In allmatches
            With oDoc.Range.Find
                .ClearFormatting
                .Replacement.ClearFormatting
                .Text = m
                .Replacement.Text = "^&"
                .Replacement.Highlight = True
                .Forward = True
                .Wrap = wdFindStop
                .Execute Replace:=wdReplaceAll
            End With
        Next m
    End If
End Function
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote