![]() |
#1
|
|||
|
|||
![]()
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 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 Thank you! Alex |
#2
|
||||
|
||||
![]() Code:
With Selection.Find .Text = "((wildcard_pattern_here)" .Replacement.Text = "original text: \1" .Replacement.Font.Bold = True .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = True .MatchWholeWord = False .MatchWildcards = True .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
![]()
All right, so the '.Format' setting was the one preventing the style change.
Thank you, it works great now! Alex |
#4
|
|||
|
|||
![]()
I would not want to open another thread just for this, so I have one more related question if you do not mind...
This RegEx matches one to ten uppercase words, divided by a space character and ending with a colon and space. Code:
.Text = "([A-Z]@ ){1,10}[A-Z]@: " .Replacement.Text = "> \1" Code:
.Text = "(([A-Z]@ ){1,10}[A-Z]@: )" .Replacement.Text = "> \1" Alex |
#5
|
|||
|
|||
![]()
Ok, problem solved, I changed the pattern with the one below and it works good now.
Code:
.Text = vbCr & "([A-Z ]{1,50}): " .Replacement.Text = "> \1" |
#6
|
||||
|
||||
![]()
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Wildcard find/replace wildcard question | hephalumph | Word | 1 | 03-12-2022 12:54 AM |
wildcard search and add (not replace) sequential numbers in front | equalizer88 | Word VBA | 4 | 05-07-2016 08:04 PM |
![]() |
rsrasc | Word VBA | 3 | 11-11-2014 03:55 PM |
Issue with Wildcard Search and Replace | linusthedog | Word | 3 | 09-04-2014 03:32 PM |
how to search and replace BOLD text >> font color change? | dylansmith | Word | 4 | 03-12-2013 09:51 PM |