October 1999
Beginner
410 pages
10h 45m
English
Performing a search and replace is not much more complicated than performing a simple search. The Find object has a Replacement child object, accessible through the Replacement property. Just set the properties of the Replacement object, including any text or formatting that you want to use for the replacement. Then we run the Execute method of the Find object, using the named parameter Replace, which can take on one of three values: wdReplaceAll, wdReplace-None, or wdReplaceOne.
Here is an example that replaces each occurrence of the word “find” with the word “replace”. Note that we must clear the formatting of both the Find and the Replacement objects.
Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "find" .Replacement.Text = "replace" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll
Read now
Unlock full access