EditReplace

Syntax

EditReplace [.Find = text] [, .Replace = text] [, .Direction = number] [, .MatchCase = number] [, .WholeWord = number] [, .PatternMatch = number] [, .SoundsLike = number] [, .FindAllWordForms = number] [, .FindNext] [, .ReplaceOne] [, .ReplaceAll] [, .Format = number] [, .Wrap = number]

Remarks

Replaces one or all instances of the specified text or formatting (or both) with different text or formatting. If there is a selection and .Wrap is omitted or set to 0 (zero), the .Find text is replaced only within the selection. The arguments for the EditReplace statement correspond to the options in the Replace dialog box.

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

The replacement text, or, to delete the text specified with .Find, an empty string (""). You specify special characters and advanced search criteria just as you do for .Find.

To specify a graphic or other nontext item as the replacement, put the item on the Clipboard and specify "^c" for .Replace.

.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.

.MatchCase

If 1, corresponds to selecting the Match Case check box

.WholeWord

If 1, corresponds to selecting the Find Whole Words Only 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)


Argument

Explanation

.SoundsLike

If 1, corresponds to selecting the Sounds Like check box

.FindAllWordForms

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

.FindNext

Finds the next instance of the text specified by .Find

.ReplaceOne

Replaces the first instance of the text specified by .Find

.ReplaceAll

Replaces all instances of the .Find text

.Format

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

0 (zero) Ignores formatting

1 Uses the specified formatting

.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) The replace operation ends and the macro continues.

1 If there is a selection, the replace operation continues in the remainder of the document. If the beginning or end of the document is reached, the replace operation continues from the opposite end.

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


Formatting is not specified within the EditReplace instruction itself. Instead, you precede EditReplace with one or more of the following statements: EditFindBorder, EditFindFont, EditFindLang, EditFindPara, EditFindStyle, EditFindTabs, EditReplaceBorder, EditReplaceFont, EditReplaceLang, EditReplacePara, EditReplaceStyle, or EditReplaceTabs. Then, in the EditReplace instruction, you set .Format to 1. Note that EditFindBorder, EditFindTabs, EditReplaceBorder, and EditReplaceTabs are available only on the Macintosh.

Here are some tips for using EditReplace effectively:

Example

This example finds all instances of underlined text in the document and replaces the format with italic. Note that the instruction .Wrap = 1 means no StartOfDocument statement is required; instances both before and after the insertion point are replaced.


EditFindClearFormatting
EditReplaceClearFormatting
EditFindFont .Underline = 1
EditReplaceFont .Italic = 1, .Underline = 0
EditReplace .Find = "", .Replace = "", .Format = 1, \
    .ReplaceAll, .Wrap = 1

See Also

EditFind, EditReplaceBorder, EditReplaceClearFormatting, EditReplaceFont, EditReplaceFrame, EditReplaceLang, EditReplacePara, EditReplaceStyle, EditReplaceTabs