Find Method (VBA Add-In Object Model)

Microsoft VBA

Find Method (VBA Add-In Object Model)

           

Searches the active module for a specified string.

Syntax

object.Find(target, startline, startcol, endline, endcol [, wholeword] [, matchcase] [, patternsearch]) As Boolean

The Find syntax has these parts:

Part Description
object Required. An object expression that evaluates to an object in the Applies To list.
target Required. A String containing the text or pattern you want to find.
startline Required. A Long specifying the line at which you want to start the search; will be set to the line of the match if one is found. The first line is number 1.
startcol Required. A Long specifying the column at which you want to start the search; will be set to the column containing the match if one is found. The first column is 1.
endline Required. A Long specifying the last line of the match if one is found. The last line may be specified as –1.
endcol Required. A Long specifying the last line of the match if one is found. The last column may be designated as –1.
wholeword Optional. A Boolean value specifying whether to only match whole words. If True, only matches whole words. False is the default.
matchcase Optional. A Boolean value specifying whether to match case. If True, the search is case sensitive. False is the default.
patternsearch Optional. A Boolean value specifying whether or not the target string is a regular expression pattern. If True, the target string is a regular expression pattern. False is the default.

Remarks

Find returns True if a match is found and False if a match isn't found.

The matchcase and patternsearch arguments are mutually exclusive; if both arguments are passed as True, an error occurs.

The content of the Find dialog box isn't affected by the Find method.

The specified range of lines and columns is inclusive, so a search can find the pattern on the specified last line if endcol is supplied as either –1 or the length of the line.