Replacement Property

Microsoft Word Visual Basic

Replacement Property

       

Returns a Replacement object that contains the criteria for a replace operation.

expression.Replacement

expression   Required. An expression that returns a Find object.

Example

This example removes bold formatting from 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
    With .Replacement
        .ClearFormatting
        .Font.Bold = False
    End With
    .Execute FindText:="", ReplaceWith:="", Format:=True, _
        Replace:=wdReplaceAll
End With

This example finds every instance of the word "Start" in the active document and replaces it with "End." The find operation ignores formatting but matches the case of the text to find ("Start").

Set myRange = ActiveDocument.Range(Start:=0, End:=0)
With myRange.Find
    .ClearFormatting
    .Text = "Start"
    With .Replacement
        .ClearFormatting
        .Text = "End"
    End With
    .Execute Replace:=wdReplaceAll, _
        Format:=True, MatchCase:=True, _
        MatchWholeWord:=True
End With