A family of Microsoft word processing software products for creating web, email, and print documents.
Change the code so that the font size is only applied when the found text is currently in 12-point text, or so that it does not touch existing 10.5-point text.
One straightforward way is to restrict the Find to text that already has a specific font size. For example, if only the 12-point instances should be changed (and 10.5-point instances must be left alone), set the Find font size instead of the Replacement font size:
Sub Rename_Trainers()
Dim FindArray As Variant
Dim ReplArray As Variant
Dim i As Long
FindArray = Array("MCKAY HARRINGTO", "RICHARDSON NORV", "D & B WEATHERLE", _
"THURLOW O'MALLE", "WALKER BERGERSO", "O'SULLIVAN SCOT")
ReplArray = Array("MCKAY HARRINGTON", "RICHARDSON NORVALL", "D & B WEATHERLEY", _
"THURLOW O'MALLEY", "WALKER BERGERSON", "O'SULLIVAN SCOTT")
For i = LBound(FindArray) To UBound(FindArray)
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
' Find only text that is already 12 pt
.Font.Size = 12
.Text = FindArray(i)
.Replacement.Text = ReplArray(i)
' Do NOT force a new font size on the replacement
' (leave .Replacement.Font.Size untouched)
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
Next i
End Sub
Key points:
-
.Font.Size = 12on the Find ensures only 12-point occurrences are matched; 10.5-point text is ignored. -
.Replacement.Font.Sizeis not set, so Word keeps the existing font size of the matched text. -
.Format = Trueis required so that the font-size condition is honored.
If instead the requirement is to always leave 10.5-point text unchanged but still force 12-point on other sizes, run two passes: one pass that finds only 10.5-point text (with .Font.Size = 10.5 and no replacement formatting) and another pass that finds all sizes and applies .Replacement.Font.Size = 12, but exclude the 10.5-point pass from the second loop.
References: