Runs the specified find operation. Returns True if the find operation is successful. Boolean.
expression.Execute(FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace, MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl)
expression Required. An expression that returns a Find object.
FindText Optional Variant. The text to be searched for. Use an empty string ("") to search for formatting only. You can search for special characters by specifying appropriate character codes. For example, "^p" corresponds to a paragraph mark and "^t" corresponds to a tab character. For a list of special characters you can use, see Find and replace text or other items.
MatchCase Optional Variant. True to specify that the find text be case sensitive. Corresponds to the Match case check box in the Find and Replace dialog box (Edit menu).
MatchWholeWord Optional Variant. True to have the find operation locate only entire words, not text that's part of a larger word. Corresponds to the Find whole words only check box in the Find and Replace dialog box.
MatchWildcards Optional Variant. True to have the find text be a special search operator. Corresponds to the Use wildcards check box in the Find and Replace dialog box.
MatchSoundsLike Optional Variant. True to have the find operation locate words that sound similar to the find text. Corresponds to the Sounds like check box in the Find and Replace dialog box.
MatchAllWordForms Optional Variant. True to have the find operation locate all forms of the find text (for example, "sit" locates "sitting" and "sat"). Corresponds to the Find all word forms check box in the Find and Replace dialog box.
Forward Optional Variant. True to search forward (toward the end of the document).
Wrap Optional Variant. Controls what happens if the search begins at a point other than the beginning of the document and the end of the document is reached (or vice versa if Forward is set to False). This argument also controls what happens if there's a selection or range and the search text isn't found in the selection or range. Can be one of the following WdFindWrap constants.
WdFindWrap can be one of these WdFindWrap constants. |
wdFindAsk After searching the selection or range, Microsoft Word displays a message asking whether to search the remainder of the document. |
wdFindContinue The find operation continues if the beginning or end of the search range is reached. |
wdFindStop The find operation ends if the beginning or end of the search range is reached. |
Format Optional Variant. True to have the find operation locate formatting in addition to or instead of the find text.
ReplaceWith Optional Variant. The replacement text. To delete the text specified by the Find argument, use an empty string (""). You specify special characters and advanced search criteria just as you do for the Find argument. To specify a graphic object or other nontext item as the replacement, move the item to the Clipboard and specify "^c" for ReplaceWith.
Replace Optional Variant. Specifies how many replacements are to be made: one, all, or none. Can be any WdReplace constant.
WdReplace can be one of these WdReplace constants. |
wdReplaceAll |
wdReplaceNone |
wdReplaceOne |
MatchKashida Optional Variant. True if find operations match text with matching kashidas in an Arabic language document. This argument may not be available to you, depending on the language support (U.S. English, for example) that you’ve selected or installed.
MatchDiacritics Optional Variant. True if find operations match text with matching diacritics in a right-to-left language document. This argument may not be available to you, depending on the language support (U.S. English, for example) that you’ve selected or installed.
MatchAlefHamza Optional Variant. True if find operations match text with matching Alef Hamzas in an Arabic language document. This argument may not be available to you, depending on the language support (U.S. English, for example) that you’ve selected or installed.
MatchControl Optional Variant. True if find operations match text with matching bidirectional control characters in a right-to-left language document. This argument may not be available to you, depending on the language support (U.S. English, for example) that you’ve selected or installed.
Remarks
If MatchWildcards is True, you can specify wildcard characters and other advanced search criteria for the FindText argument. For example, "*(ing)" finds any word that ends in "ing."
To search for a symbol character, type a caret (^), a zero (0), and then the symbol's character code. For example, "^0151" corresponds to an em dash (
Unless otherwise specified, replacement text inherits the formatting of the text it replaces in the document. For example, if you replace the string "abc" with "xyz," occurrences of "abc" with bold formatting are replaced with the string "xyz" with bold formatting.
Also, if MatchCase is False, occurrences of the search text that are uppercase will be replaced with an uppercase version of the replacement text regardless of the case of the search and replacement text. Using the previous example, occurrences of "ABC" are replaced with "XYZ."
Execute method as it applies to the Dialog and KeyBinding objects.
Dialog object: Applies the current settings of a Microsoft Word dialog box.
KeyBinding object: Runs the command associated with the specified key combination.
expression.Execute
expression Required. An expression that returns one of the above objects.
Execute method as it applies to the MailMerge object.
Performs the specified mail merge operation.
expression.Execute(Pause)
expression Required. An expression that returns one of the above objects.
Pause Optional Variant. True for Microsoft Word pause and display a troubleshooting dialog box if a mail merge error is found. False to report errors in a new document.
Example
As it applies to the Find object.
This example finds and selects the next occurrence of the word "library."
With Selection.Find
.ClearFormatting
.MatchWholeWord = True
.MatchCase = False
.Execute FindText:="library"
End With
This example finds all occurrences of the word "hi" in the active document and replaces each occurrence with "hello."
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="hi", _
ReplaceWith:="hello", Replace:=wdReplaceAll
As it applies to the Dialog object.
The following example enables the Keep with next check box on the Line and Page Breaks tab in the Paragraph dialog box.
With Dialogs(wdDialogFormatParagraph)
.KeepWithNext = 1
.Execute
End With
As it applies to the KeyBinding object.
This example assigns the CTRL+SHIFT+C key combination to the FileClose command and then executes the key combination (the document is closed).
CustomizationContext = ActiveDocument.AttachedTemplate
Keybindings.Add KeyCode:=BuildKeyCode(wdKeyControl, _
wdKeyShift, wdKeyC), KeyCategory:=wdKeyCategoryCommand, _
Command:="FileClose"
FindKey(BuildKeyCode(wdKeyControl, wdKeyShift, wdKeyC)).Execute
As it applies to the MailMerge object.
This example executes a mail merge if the active document is a main document with an attached data source.
Set myMerge = ActiveDocument.MailMerge
If myMerge.State = wdMainAndDataSource Then MyMerge.Execute