Microsoft 365 and Office | Word | For home | Windows
A family of Microsoft word processing software products for creating web, email, and print documents.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello from Steve
In the below script I would like to add please Font 12
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
.Text = FindArray(i)
.Replacement.Text = ReplArray(i)
.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
A family of Microsoft word processing software products for creating web, email, and print documents.
AI answer
Add formatting for the replacement text by setting the Font.Size on the Replacement formatting before executing Find.Execute.
For example, to make all replaced trainer names use font size 12:
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
.Text = FindArray(i)
.Replacement.Text = ReplArray(i)
' Apply font size 12 to the replacement text
.Replacement.Font.Size = 12
.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
This keeps the existing find/replace behavior and ensures that each replaced name is formatted with font size 12.
References: