Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #25  
Old 01-06-2025, 11:16 AM
vivka vivka is online now Regex-pattern Windows 7 64bit Regex-pattern Office 2016
Expert
 
Join Date: Jul 2023
Posts: 294
vivka is on a distinguished road
Default

Or another presentation of Greg's idea:
Code:
Sub ScratchMacro()
'Coded by Gregory K. Maxey
'https://www.msofficeforums.com/184580-post31.html

 Dim oRng As range
  Set oRng = ActiveDocument.range
  With oRng.Find
    .text = "<[0-9]{4,5}>"
    .MatchWildcards = True
    While .Execute
        If InStr(oRng.text, "2") > 0 Then MsgBox oRng.text
    Wend
  End With
lbl_Exit:
  Exit Sub
  End Sub
However I had situations when regex helped me out, unlike VBA. Maybe it was because of my poor VBA knowledge.
Greg and Batman1, thank you for another good lesson!
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex-pattern Capture group in RegEx alex100 Word VBA 1 01-02-2021 02:39 PM
Regex-pattern Regex over 700 matches in a long doc totoMSOF Word VBA 19 03-11-2019 01:28 PM
Regex-pattern Using VB Regex feature, I tried to replace 'the' and 'this' with 'that' but got screwed abdan Word VBA 3 01-18-2019 09:38 PM
Macro help regex subspace3 Word VBA 1 10-15-2014 09:53 AM
Regex in Word: Replaced strings are in disorder chgeiselmann Word 0 04-26-2009 11:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:21 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