![]() |
|
|||||||
|
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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] |
|
#3
|
||||
|
||||
|
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 |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Issue with Accented Letter Replacement (Upper/Lower Case)
|
onlywonderboy | Word VBA | 1 | 12-21-2017 08:57 PM |
How to stop Word from capitalizing the first letter?
|
mobileone | Word | 2 | 08-27-2016 07:17 PM |
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 |
Replace is capitalizing the first letter of the first word
|
Beachhouse | Word | 1 | 02-07-2012 03:36 PM |