EditFind

Syntax

EditFind [.Find = text] [, .Replace = text] [, .Direction = number] [, .WholeWord = number] [, .MatchCase = number] [, .PatternMatch = number] [, .SoundsLike = number]
[, .FindAllWordForms = number] [, .Format = number] [, .Wrap = number]

Remarks

Finds the next instance of the specified text, formatting, or both. The arguments for the EditFind statement correspond to the options in the Find dialog box (Edit menu). Used in a While¼Wend loop, EditFind can be extremely useful when you need to repeat a series of instructions each time a certain piece of text or formatting is found in your document. Many examples in "Statements and Functions" illustrate this common use of EditFind.

Argument

Explanation

.Find

The text to find, or, to search for formatting only, an empty string (""). You can search for special characters, such as paragraph marks, by specifying appropriate character codes. For example, "^p" corresponds to a paragraph mark and "^t" corresponds to a tab character.

If .PatternMatch is set to 1, you can specify wildcard characters and other advanced search criteria. For example, "*(ing)" finds any word ending in "ing."

To search for a symbol character, specify the symbol's character code following a caret (^) and a zero (0). In Windows, for example, "^0151" corresponds to an em dash ( — ).

.Replace

You may need to set .Replace to an empty string ("") to avoid an error. For example, if you set .PatternMatch to 1 and the replacement text currently in the Replace dialog box is not valid with pattern matching on, an error occurs.

.Direction

The direction to search:

0 (zero) Searches toward the end of the document.

1 Searches toward the beginning of the document.

The default is the direction used in the previous search or 0 (zero) the first time the Find or Replace command is run.

.WholeWord

If 1, corresponds to selecting the Find Whole Words Only check box.

.MatchCase

If 1, corresponds to selecting the Match Case check box.

.PatternMatch

If 1, Word evaluates .Find as a string containing advanced search criteria such as the asterisk (*) and question mark (?) wildcard characters (corresponds to selecting the Use Pattern Matching check box).

.SoundsLike

If 1, corresponds to selecting the Sounds Like check box.

.FindAllWordForms

If 1, corresponds to selecting the Find All Word Forms check box.

.Format

Finds formatting in addition to, or instead of, text:

0 (zero) Ignores formatting

1 Uses the specified formatting


Argument

Explanation

.Wrap

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 .Direction is set to 1). The .Wrap argument also controls what happens if there is a selection and the search text is not found in the selection.

0 (zero) or omitted The search operation ends and the macro continues.

1 If there is a selection, Word searches the remainder of the document. If the beginning or the end of the document is reached, Word continues the search from the opposite end.

2 If there is a selection, Word displays a message asking whether to search the remainder of the document. If the beginning or the end of the document is reached, Word displays a message asking whether to continue the search from the opposite end.


Formatting is not specified within the EditFind instruction itself. Instead, you precede EditFind with one or more EditFindBorder, EditFindFont, EditFindLang, EditFindPara, EditFindStyle, or EditFindTabs instructions. Then, in the EditFind instruction, you set .Format to 1. Note that EditFindBorder and EditFindTabs are available only on the Macintosh.

Here are some tips for using EditFind effectively:

Examples

This example finds the next instance of "Trey Research" with single-underline formatting:


EditFindClearFormatting            'Clear leftover formats
EditFindFont .Underline = 1
EditFind .Find = "Trey Research", .Direction = 0, \
    .WholeWord = 0, .MatchCase = 0, .Format = 1

The following example inserts the string "Tip: " at the beginning of every Heading 6 paragraph. The instructions StartOfDocument and While EditFindFound() are key to any macro that repeats a series of actions each time the specified item is found.


StartOfDocument
EditFindClearFormatting
EditFindStyle .Style = "Heading 6"
EditFind .Find = "", .Direction = 0, .Format = 1, .Wrap = 0
While EditFindFound()
    StartOfLine
    Insert "Tip: "
    EditFindStyle .Style = "Heading 6"
    EditFind .Find = "", .Direction = 0, .Format = 1, .Wrap = 0
Wend

See Also

EditFindClearFormatting, EditFindBorder, EditFindFont, EditFindFound(), EditFindFrame, EditFindLang, EditFindPara, EditFindStyle, EditFindTabs, EditReplace