Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-14-2025, 01:40 AM
rekent rekent is offline Word Macro to Find a phrase followed by a number and a lower case letter, capitalizing the letter Windows 10 Word Macro to Find a phrase followed by a number and a lower case letter, capitalizing the letter Office 2016
Novice
Word Macro to Find a phrase followed by a number and a lower case letter, capitalizing the letter
 
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
  #2  
Old 01-14-2025, 05:10 AM
macropod's Avatar
macropod macropod is offline Word Macro to Find a phrase followed by a number and a lower case letter, capitalizing the letter Windows 10 Word Macro to Find a phrase followed by a number and a lower case letter, capitalizing the letter Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,374
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If your figure references use Word's cross-referencing, no amount of changing the case via Find/Replace will have a lasting effect on them, since they'll revert any time something causes the references to update. You'll need to either change them at the source or add an \* Upper switch to the cross-reference fields - the former is preferable.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-14-2025, 01:45 PM
Guessed's Avatar
Guessed Guessed is offline Word Macro to Find a phrase followed by a number and a lower case letter, capitalizing the letter Windows 10 Word Macro to Find a phrase followed by a number and a lower case letter, capitalizing the letter Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,163
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

As Paul suggested, this is not simple if the figure numbers and/or letters are fields (and they should be either seq or ref fields) but as you wrote the examples showing just text here is a possible solution that doesn't go for the bonus points.
Code:
  With ActiveDocument.Content.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Replacement.Font.AllCaps = True
    .Text = "FIG[.sS]{1,2} [1-9]{1,}[a-z]"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchKashida = False
    .MatchDiacritics = False
    .MatchAlefHamza = False
    .MatchControl = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
  End With
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Macro to Find a phrase followed by a number and a lower case letter, capitalizing the letter Issue with Accented Letter Replacement (Upper/Lower Case) onlywonderboy Word VBA 1 12-21-2017 08:57 PM
Word Macro to Find a phrase followed by a number and a lower case letter, capitalizing the letter How to stop Word from capitalizing the first letter? mobileone Word 2 08-27-2016 07:17 PM
Word Macro to Find a phrase followed by a number and a lower case letter, capitalizing the letter Find and replace with a macro, problem with letter case garcanrya Word VBA 2 01-10-2014 05:40 AM
Repeatedly capitalizing first letter of a word in a document Microsoftenquirer1000 Word 1 02-21-2013 07:36 PM
Word Macro to Find a phrase followed by a number and a lower case letter, capitalizing the letter Replace is capitalizing the first letter of the first word Beachhouse Word 1 02-07-2012 03:36 PM

Other Forums: Access Forums

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