View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Myrna Larson Myrna Larson is offline
external usenet poster
 
Posts: 863
Default get linenumber when string found in VBE codemodule

How are you searching for the string? If it's via the Find method in the VBIDE
library, you find the following in Help.

Note the comments re the StartLine argument, specifically that if the string
is found, the argument is set to the line number where it was found.

Is that what you need?

"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

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.


On Sat, 9 Oct 2004 19:22:20 +0100, "RB Smissaert"
wrote:

How do I programmatically get the linenumber of the first line in a code
module where a specified string is found?
I can see if a string was found or not, but there seems to be no way to get
the line number, other
than running a loop and checking a number of lines.

RBS