Replacement Object

Description

Represents the replace criteria for a find-and-replace operation. The properties and methods of the Replacement object correspond to the options in the Find and Replace dialog box.

Using the Replacement Object

Use the Replacement property to return a Replacement object. The following example replaces the next occurrence of the word "hi" with the word "hello."

With Selection.Find
    .Text = "hi"
    .ClearFormatting
    .Replacement.Text = "hello"
    .Replacement.ClearFormatting
    .Execute Replace:=wdReplaceOne, Forward:=True
End With
To find and replace formatting, set both the find text and the replace text to empty strings (""), and set the Format argument of the Execute method to True. The following example removes all the bold formatting in the active document. The Bold property is True for the Find object and False for the Replacement object.

With ActiveDocument.Content.Find
    .ClearFormatting
    .Font.Bold = True
    .Text = ""
    With .Replacement
        .ClearFormatting
        .Font.Bold = False
        .Text = ""
    End With
    .Execute Format:=True, Replace:=wdReplaceAll
End With
Properties

Application property, Creator property, Font property, Frame property, Highlight property, LanguageID property, LanguageIDFarEast property, ParagraphFormat property, Parent property, Style property, Text property.

Methods

ClearFormatting method.

See Also

Find object.