Replace Method

Microsoft PowerPoint Visual Basic

ShowReplace method as it applies to the 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.

expression.Replace(FindWhat, ReplaceWhat, After, MatchCase, WholeWords)

expression    Required. An expression that returns one of the above objects.

FindWhat   Required String. The text to search for.

ReplaceWhat   Required String. The text you want to replace the found text with.

After   Optional Integer. 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 MsoTriState. Determines whether a distinction is made on the basis of case.

MsoTriState can be one of these MsoTriState constants.
msoCTrue
msoFalse Default.
msoTriStateMixed
msoTriStateToggle
msoTrue Distinguish between uppercase and lowercase characters.

WholeWords   Optional MsoTriState. Determines whether only whole words are found.

MsoTriState can be one of these MsoTriState constants.
msoCTrue
msoFalse Default.
msoTriStateMixed
msoTriStateToggle
msoTrue Find only whole words, and not parts of larger words.

ShowReplace method as it applies to the Fonts object.

Replaces a font in the Fonts collection.

expression.Replace(Original, Replacement)

expression    Required. An expression that returns one of the above objects.

Original   Required String. The name of the font to replace.

Replacement   Required String. The the name of the replacement font.

Example

ShowAs it applies to the TextRange object.

This example replaces every whole-word occurrence of "like" in all of the shapes in the active presentation with "NOT LIKE".

Sub ReplaceText()
    
    Dim oSld As Slide
    Dim oShp As Shape
    Dim oTxtRng As TextRange
    Dim oTmpRng As TextRange
     
    Set oSld = Application.ActivePresentation.Slides(1)
    
    For Each oShp In oSld.Shapes
        Set oTxtRng = oShp.TextFrame.TextRange
        Set oTmpRng = oTxtRng.Replace(FindWhat:="like", _
            Replacewhat:="NOT LIKE", WholeWords:=True)
        Do While Not oTmpRng Is Nothing
            Set oTxtRng = oTxtRng.Characters(oTmpRng.Start + oTmpRng.Length, _
                oTxtRng.Length)
            Set oTmpRng = oTxtRng.Replace(FindWhat:="like", _
                Replacewhat:="NOT LIKE", WholeWords:=True)
        Loop
    Next oShp

End Sub
				

ShowAs it applies to the Fonts object.

This example replaces the Times New Roman font with the Courier font in the active presentation.

Application.ActivePresentation.Fonts _
    .Replace Original:="Times New Roman", Replacement:="Courier"