Replacement object (Word)
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.
Remarks
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
Methods
Name |
---|
ClearFormatting |
Properties
Name |
---|
Application |
Creator |
Font |
Frame |
Highlight |
LanguageID |
LanguageIDFarEast |
NoProofing |
ParagraphFormat |
Parent |
Style |
Text |
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for