Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 04-20-2018, 04:10 PM
macropod's Avatar
macropod macropod is offline Regular expressions and field codes Windows 7 64bit Regular expressions and field codes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular expressions and field codes regular expressions in footnotes loes Word 3 09-04-2019 07:52 AM
Word Regular Expressions: zero or more occurences? tinfanide Word 6 09-16-2015 03:13 PM
Regular expressions and field codes Regular Expressions: match words within quotes? tinfanide Word VBA 3 02-02-2013 10:07 PM
regular expressions for empty lines eNGiNe Word 1 01-21-2013 06:38 AM
Regular expressions and field codes Regular Expressions: [!0-9] does not work??? tinfanide Excel Programming 4 05-30-2012 04:09 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:36 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft