Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-24-2023, 06:13 AM
alex100 alex100 is offline Search & replace: capture wildcard groups and set a bold formatting Windows 7 64bit Search & replace: capture wildcard groups and set a bold formatting Office 2016
Advanced Beginner
Search & replace: capture wildcard groups and set a bold formatting
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default Search & replace: capture wildcard groups and set a bold formatting

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
Reply With Quote
 



Similar Threads
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
Search & replace: capture wildcard groups and set a bold formatting Find/Replace Wildcard Needed-Bold & Highlight 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

Other Forums: Access Forums

All times are GMT -7. The time now is 12:34 AM.


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