View Single Post
 
Old 01-14-2025, 01:40 AM
rekent rekent is offline Windows 10 Office 2016
Novice
 
Join Date: May 2014
Posts: 23
rekent is on a distinguished road
Default Word Macro to Find a phrase followed by a number and a lower case letter, capitalizing the letter

Hello. I am trying to search a document for the phrase FIG., FIGs. or FIGS. followed by any number and a lower case letter. For example, FIG. 1a. I'm wanting to capitalize the A so that the resulting text is FIG. 1A.

I thought this would do it, but it doesn't, and I'm not sure where I went wrong. The find and basic replace are straightforward enough that I assume it has to be in the UCase portion. Any guidance on where I went wrong?

Code:
With ActiveDocument.Content.Find
  .Text = "(FIG. [1-9])([a-z])"
  .Replacement.Text = "\1"UCase(\2)
  .MatchWildcards = true
  .Text = "(FIG[Ss]. [1-9])([a-z])"
  .Replacement.Text = "\1"UCase(\2)
  .MatchWildcards = true
End With
Bonus points if anyone has an idea on how to tackle a string of multiple similar to "FIGS. 1a, 3b, ..., and 11f ...".
Reply With Quote