O'Reilly logo

Writing Word Macros, Second Edition by Steven Roman PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Execute Method

The Execute method of the Find object actually has a number of parameters that allow an alternative syntax for doing a search and replace. The full syntax of the Execute method is:

FindObject.Execute(FindText, MatchCase, MatchWholeWord, _
	MatchWildcards, MatchSoundsLike, MatchAllWordForms, _
	Forward, Wrap, Format, ReplaceWith, Replace)

For instance, the previous search and replace could have been coded as follows:

	Selection.Find.ClearFormatting
	Selection.Find.Replacement.ClearFormatting
	Selection.Find.Execute _
	   FindText:="find", _
	   ReplaceWith:="replace", _
	   Forward:=True, _
	   Wrap:=wdFindContinue, _
	   MatchCase:=False, _
	   MatchWholeWord:=False, _
	   MatchWildcards:=False, _
	   MatchSoundsLike:=False, _
	   MatchAllWordForms:=False, _
	   replace:=wdReplaceAll

This syntax seems to be a bit less readable than the previous one, but you may run across it when reading other code.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required