Replacement Object (Word)

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

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.

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" 
 .Replacement.Text = "hello" 
 .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 
 .Font.Bold = True 
 .Text = "" 
 With .Replacement 
 .Font.Bold = False 
 .Text = "" 
 End With 
 .Execute Format:=True, Replace:=wdReplaceAll 
End With