Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-22-2023, 01:27 AM
mrbolty mrbolty is offline vba macro to remove wildcard patterns and replace with static Windows 11 vba macro to remove wildcard patterns and replace with static Office 2019
Novice
vba macro to remove wildcard patterns and replace with static
 
Join Date: Jan 2023
Posts: 2
mrbolty is on a distinguished road
Question vba macro to remove wildcard patterns and replace with static

Hi



I can't seem to make this work, i simply want to have a button in word that will run a macro to remove preset, wildcard, pattern of text and replace them with a single word

There will be multiple patterns but a single replaced word in every case

For example

find a number starting with 012 and being 10 characters long and replace with REMOVED
find an email address and replace with REMOVED

Each time having an iterative list thus of things to find but always replacing with a static text.

I tried a find string but i'm struggling with the wildcard aspect, could anyone help with an example please?

Thanks

RC
Reply With Quote
  #2  
Old 01-22-2023, 05:33 AM
gmayor's Avatar
gmayor gmayor is offline vba macro to remove wildcard patterns and replace with static Windows 10 vba macro to remove wildcard patterns and replace with static Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

<012[0-9]{7}> will find your ten digit number beginning 012
[a-zA-Z0-9._-]{1,}\@[a-zA-Z0-9._-]{1,} should find your e-mail addresses
See Replace using wildcards and Document Batch Processes
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 01-22-2023, 07:30 AM
mrbolty mrbolty is offline vba macro to remove wildcard patterns and replace with static Windows 11 vba macro to remove wildcard patterns and replace with static Office 2019
Novice
vba macro to remove wildcard patterns and replace with static
 
Join Date: Jan 2023
Posts: 2
mrbolty is on a distinguished road
Default

thanks, however i have zero va knowledge of how to put this in a macro and a button in a document.

Any help towards that or resources would be appreciated, what i created thus far just doesn't seem to work so i prob need to start afresh.
Reply With Quote
  #4  
Old 01-22-2023, 09:19 AM
AlanCantor AlanCantor is offline vba macro to remove wildcard patterns and replace with static Windows 10 vba macro to remove wildcard patterns and replace with static Office 2019
Competent Performer
 
Join Date: Nov 2020
Posts: 137
AlanCantor is on a distinguished road
Default

This will get you close:


Code:
Sub Remove012PhoneNumbers()
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "<012[0-9]{7}>"
        .Replacement.Text = "REMOVED"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Reply With Quote
  #5  
Old 01-23-2023, 09:56 PM
gmayor's Avatar
gmayor gmayor is offline vba macro to remove wildcard patterns and replace with static Windows 10 vba macro to remove wildcard patterns and replace with static Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

See Document Batch Processes and the replace table pairs option. Put the search strings and what they are to be replaced with in the table. No programming knowledge is required.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
vba macro to remove wildcard patterns and replace with static How to code a Find&Replace macro to remove a tab and bold the entire para Frogoogue Word VBA 4 05-30-2022 09:15 AM
Wildcard find/replace wildcard question hephalumph Word 1 03-12-2022 12:54 AM
vba macro to remove wildcard patterns and replace with static Static Folder Locations to Automate a Find and Replace using Word VBA rmoyar Word VBA 9 01-29-2020 02:35 PM
Macro for Find/replace to remove space before Hard Return AlfredStreich Word VBA 4 01-23-2020 03:59 PM
Need Help With Find and Replace Wildcard rsrasc Word VBA 9 10-13-2015 02:37 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:38 PM.


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