ReplaceText Method

Home Page (Objects)OverviewFAQReference

Applies to: TextDocument object, TextSelection object

Replaces all instances of a string or regular expression with another string or regular expression.

Syntax

object.ReplaceText ( CurrString, RepString [, flags] )

Parameters

object

An expression that evaluates to a TextDocument object or a TextSelection object.

CurrString

The String you want to replace.

RepString

The replacement String.

flags

(Optional) A string constant of type DsTextSearchOptions that determines how to conduct the search. To perform complex searches, you can combine values. The values you can use singly or in combination are:

Return Values

The ReplaceText method returns one of the following values:

Remarks

The following table summarizes the results of using the ReplaceText method with the objects in the Applies To list:

Object Results
TextDocument Replaces all instances of the specified text string in the entire document.
TextSelection Replaces all instances of the specified text string in the current selection.

You can combine string constants in the flags parameter by using the or or + operators. For example, to conduct a case-sensitive forward search, you could specify dsMatchForward or dsMatchCase or dsMatchForward + dsMatchCase. However, you can use only one of the regular expression values at a time. For example, you cannot combine dsMatchRegExpCur with dsMatchRegExpE.

Example

In the current selection, the following example replaces all occurrences of "LPVOID" with "void *" by using tagged regular expressions:

Sub ReplaceLPVOID
   ActiveDocument.Selection.ReplaceText "LPVOID",    "void *", dsMatchCase + dsMatchWord
End Sub

See Also   FindText method, MarkText method.