Replace Method
Applies To
Fonts collection object, TextRange object.
Description
TextRange object: Finds specific text in a text range, replaces the found text with a specified string, and returns a TextRange object that represents the first occurrence of the found text. Returns Nothing if no match is found.
Fonts collection: Replaces a font in the Fonts collection.
Syntax 1
expression.Replace(FindWhat, ReplaceWhat, After, MatchCase, WholeWords)
Syntax 2
expression.Replace(Original, Replacement)
expression Required. An expression that returns a TextRange object (Syntax 1) or a Fonts collection (Syntax 2).
FindWhat Required String. The text to search for.
ReplaceWhat Required String. The text you want to replace the found text with.
After Optional Long. The position of the character (in the specified text range) after which you want to search for the next occurrence of FindWhat. For example, if you want to search from the fifth character of the text range, specify 4 for After. If this argument is omitted, the first character of the text range is used as the starting point for the search.
MatchCase Optional Long. True to have the search distinguish between uppercase and lowercase characters. The default value is False.
WholeWords Optional Long. True to have the search find only whole words, and not parts of larger words. The default value is False.
Original Required String. The name of the font to replace.
Replacement Required String. The name of the replacement font.
See Also
Find method.
Example
This example replaces every whole-word occurrence of "CompanyX" in the active presentation with "CompanyY."
For Each sld In Application.ActivePresentation.Slides
For Each shp In sld.Shapes
shp.TextFrame.TextRange.Replace FindWhat:="CompanyX", _
Replacewhat:="CompanyY", WholeWords:=True
Next shp
Next sld
This example replaces the Times New Roman font with the Courier font in the active presentation.
Application.ActivePresentation.Fonts.Replace "Times New Roman", _
"Courier"