I would like to replace some keywords using wildcards, while also capturing the wildcard group and applying bold formatting to the matches. I have two codes so far, but neither one accomplishes both requirements.
The first code captures the group but does not set the bold formatting:
Code:
With Selection.Find
.Text = "(wildcard_pattern_here)"
.Replacement.Text = "original text: \1"
.Replacement.Font.Bold = True
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute replace:=wdReplaceAll
The second code does the exact opposite - applies the bold formatting but does not insert captured groups in the replacement text:
Code:
With Selection.Find
.Text = "(wildcard_pattern_here)"
.Replacement.Text = "original text: \1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
Do While .Execute
Selection.Font.Bold = True
Selection.TypeText Text:=.Replacement.Text
Loop
End With
How can I achieve both requirments at the same time, please?
Thank you!
Alex