Share via


FindText Method

Home Page (Objects)OverviewFAQReference

Applies to: TextSelection object

Starting after the current selection, FindText searches the rest of a document for a specified string. If the string is found, FindText moves the selection to that string.

Syntax

object**.FindText(string [,**flags] )

Parameters

object

An expression that evaluates to a TextSelection object.

string

A String that represents the string you want to find.

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:

  • dsMatchForward   Starts a forward search. This is the default.

  • dsMatchBackward   Starts a backward search.

  • dsMatchFromStart   Starts a search from the beginning or end of the document. If you specify a forwards search (dsMatchForward), the search starts from the beginning of the document. Alternatively, if you specify a backwards search (dsMatchBackward), the search starts from the end of the document.

  • dsMatchWord   Requires that whole words match.

  • dsMatchCase   Requires a case-sensitive match.

  • dsMatchRegExp   Requires a match with Developer Studio regular expressions.

  • dsMatchNoRegExp   Does not require a match with Developer Studio regular expressions. This is the default.

  • dsMatchRegExpB Requires a match with BRIEF® regular expressions.

  • dsMatchRegExpE   Requires a match with Epsilon™ regular expressions.

  • dsMatchRegExpCur   Requires a match using the current regular expression setting.

Return Values

The FindText method returns one of the following values:

  • True   If the search is successful.

  • False   If the search is not successful.

Remarks

You can combine values in the flags parameter by using the Or (or) or Concatenation (+) 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

The following example conducts a case-sensitive search for the word "main":

Sub FindMain
   ActiveDocument.Selection.FindText    "main",dsMatchCase + dsMatchWord
End Sub

See Also   MarkText method, ReplaceText method.