#1
|
|||
|
|||
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 |
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 |
VBScript.RegExp: exclude a particular word | tinfanide | Excel Programming | 2 | 06-07-2012 06:52 AM |
WORD: Rtf and search-replace (regexp/fonts) | seteshpl | Word | 1 | 09-06-2011 01:35 AM |
Help with find and replace or query and replace | shabbaranks | Excel | 4 | 03-19-2011 08:38 AM |