Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-05-2021, 11:36 AM
yogis4031 yogis4031 is offline Replace the layout of a regexp Windows 10 Replace the layout of a regexp Office 2019
Novice
Replace the layout of a regexp
 
Join Date: Oct 2021
Posts: 1
yogis4031 is on a distinguished road
Default Replace the layout of a regexp

Hello all,


I've written a macro to replace and update a keyword starting with '#(\d\w)' in a word document but my code seems not working.


Nothing is updated.
Do you have any advice or clue to fix it ?

Sub UpdateData()
Dim RegexObject As RegExp
Dim RegexMatches As MatchCollection
Dim RegexMatch As Match

' Create an object RegExp


Set RegexObject = New RegExp

' Customize the RegExp object
With RegexObject
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = "#(\d\w)+"
Set RegexMatches = .Execute(Selection.Text)
End With
' Search all keywords
With Selection.Find
.ClearFormatting
.Forward = True
.Format = False
.MatchCase = True

For Each RegexMatch In RegexMatches
.Text = RegexMatch
.Execute

' Select the keyword and update the color
With Selection
.Font.Color = wdColorPink
End With
Next RegexMatch
End With

End Sub
Reply With Quote
Reply

Tags
regex, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
In Find and Replace, can Word stop after each Replace? wardw Word 1 06-08-2017 02:47 PM
RegExp: tinfanide Word VBA 0 06-08-2014 08:52 AM
Replace the layout of a regexp VBScript.RegExp: exclude a particular word tinfanide Excel Programming 2 06-07-2012 06:52 AM
Replace the layout of a regexp WORD: Rtf and search-replace (regexp/fonts) seteshpl Word 1 09-06-2011 01:35 AM
Replace the layout of a regexp Help with find and replace or query and replace shabbaranks Excel 4 03-19-2011 08:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:03 AM.


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