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
|