Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 06-13-2018, 08:58 AM
d4okeefe d4okeefe is offline Find and replace numbers (up to three digits) Windows 10 Find and replace numbers (up to three digits) Office 2016
Advanced Beginner
 
Join Date: Apr 2013
Posts: 77
d4okeefe is on a distinguished road
Default

With VBA, you can probably simply find and replace with wildcards, rather than use the <Microsoft VBScript Regular Expressions 5.5> library. Although you could use that too. The advantage of regex, in my experience, is that it allows you to identify substrings of zero or more instances, whereas Word's wildcards do not.

For the example you give, you can do something like this with Wildcards

Code:
Sub find_replace_yearbook()
    Dim d As Document: Set d = ActiveDocument
    Dim r As Range: Set r = d.Content
    
    Dim Author1 As String, ArticleTitle1 As String
    Author1 = "NameOfAuthor"
    ArticleTitle1 = "NameOfArticle"
    
    r.Find.ClearFormatting
    r.Find.Replacement.ClearFormatting
    r.Find.Text = "yearbook ([0-9]{4}, p. )[0-9]{1,}"
    r.Find.MatchWildcards = True
    r.Find.Replacement.Text = Author1 + ", " + ArticleTitle1 + ", YB \1" + "2-137"
    r.Find.Execute Replace:=wdReplaceAll
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and replace numbers (up to three digits) Find and Replace - How to insert brackets around all numbers in a doc Natedogg Word 2 05-21-2015 07:16 AM
Find and replace BETWEEN numbers WordUser2015 Word 4 12-19-2014 02:09 PM
find and replace consecutive numbers kpl_39 Word 1 06-07-2013 05:04 AM
Find and replace numbers (up to three digits) Find & Replace formula for numbers? Griff Word 4 04-18-2011 02:47 AM
Find and replace page numbers in body of text tollanarama Word 3 02-13-2011 06:00 AM

Other Forums: Access Forums

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