Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-22-2022, 03:53 AM
marcotte974 marcotte974 is offline Find and replace text in a document with wildcards in vba Windows 8 Find and replace text in a document with wildcards in vba Office 2013
Novice
Find and replace text in a document with wildcards in vba
 
Join Date: Jun 2022
Posts: 2
marcotte974 is on a distinguished road
Default Find and replace text in a document with wildcards in vba


Salut ŕ toute la communauté
To find generic words in a word document and surround them with square brackets I use the following macro and it works:
Code:
Sub test()
Dim rngDoc As Word.Range
Dim sArray As Variant, tArray As Variant
Dim i As Long
sArray = Array("ABCD.0001/0002/0003")
tArray = Array("ABCD.0001", "ABCD.0002", "ABCD.0003")

Set rngDoc = ActiveDocument.Range
For i = 0 To UBound(sArray)
    With rngDoc.Find
        .ClearFormatting
        .Text = sArray(i)
        .Replacement.Text = "ABCD.0001 ABCD.0002 ABCD.0003"
        .Execute Replace:=wdReplaceAll
    End With
Next
For i = 0 To UBound(tArray)
    With rngDoc.Find
        .ClearFormatting
        .Text = tArray(i)
        .Replacement.Text = "[" & tArray(i) & "]"
        .Execute Replace:=wdReplaceAll
    End With
Next
 End Sub
Is it possible to replace my tArray with an expression like "ABCD.[0-9]{4}" because my generic words can go from ABCD.0001 to ABCD.9999?
Thank you
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and replace text in a document with wildcards in vba Help with WildCards Find & Replace either or nothing... Cendrinne Word VBA 9 11-14-2020 08:25 AM
Advanced Find and Replace with Wildcards help needed Amapola188 Word 3 07-23-2019 10:54 PM
Find and replace text in a document with wildcards in vba Find and replace text with wildcards arunchandar9 Word VBA 15 06-30-2019 01:06 AM
Using wildcards how do I Find and Add to, not replace Stargehzer Word 3 01-25-2016 09:14 PM
Find & Replace: Wildcards (except this pattern) tinfanide Word 6 01-26-2014 06:39 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:14 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