Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 01-11-2024, 05:22 AM
syl3786 syl3786 is offline Word macro wildcard issue Windows 10 Word macro wildcard issue Office 2019
Advanced Beginner
Word macro wildcard issue
 
Join Date: Jan 2023
Posts: 97
syl3786 is on a distinguished road
Default

Quote:
Originally Posted by vivka View Post
Hi! This is the fastest way, otherwise you'll have to work with a range & then move it one char to the left in each loop:
Code:
   
    With selection.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Forward = True
        .Wrap = wdFindStop
        .Format = True
        .MatchWildcards = True
        .text = Chr(9) & "1([!0-9])"
        .Replacement.text = Chr(9) & "-\1"
        .Execute Replace:=wdReplaceAll
        .text = Chr(9) & "-"
        .Replacement.text = ""
        .Replacement.Font.ColorIndex = wdRed
        .Execute Replace:=wdReplaceAll
    End With
Notes: 1) there's no need for {1}; 2) Chr(9) can be used instead of vbTab, which I did; 3) Instead of 'selection.range.Find' you can use 'ActiveDocument.range.Find' & delete 'selection.HomeKey Unit:=wdStory, Extend:=wdMove' making the code shorter; 4) Tracking changes may be faulty (for an unknown reason, at least in my Word 2016), so disabling it can do no harm because the changes will be colored red & visible. Or you can color changes, say, blue if there are red strings in your doc.
Thank you so much for your assistance! Your suggestion was incredibly insightful and I had not considered that approach before. Your intelligence and problem-solving skills are truly impressive!
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Recording macro for Find Wildcard 2vbr Word VBA 3 09-21-2020 05:29 PM
Word macro wildcard issue Macro to highlight wildcard phrase, copy and paste into new doc. MaryTom Word VBA 2 05-18-2018 04:23 PM
Issue with wildcard search mysterytramp Word 0 05-13-2015 10:40 AM
Issue with Wildcard Search and Replace linusthedog Word 3 09-04-2014 03:32 PM
Change characters outside a wildcard while keeping wildcard results nymusicman Word VBA 2 04-10-2014 08:17 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:32 PM.


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