Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Procedure name/Current Line number

41 views
Skip to first unread message

Jos Vens

unread,
Dec 8, 2001, 5:44:19 PM12/8/01
to
Hi,

Is there a way to know what the current procedure-running is? My problem is
equally solved if there's a way to know what the current line of code is

I know this statement

MsgBox Application.VBE.ActiveCodePane.CodeModule.ProcOfLine(vCurrentLine,
vbext_pk_Proc)

This gives me the procedure-name that is on line vCurrentLine in the active
module. (eg. vCurrentLine = 5)

I want to write a general error procedure that gives me the procedure-name
of the procedure that generates the error without explitely giving it
through

On error goto Herror
.
.
.
Exit Sub

Herror:

Err_Log vProcName, vLinenumber
Resume next

End sub

Chip Pearson

unread,
Dec 8, 2001, 6:52:10 PM12/8/01
to
Unfortunately, there is no good way to do this. There is no built-in way to
determine what procedure is currently executing. If you have line numbers (not
text labels) in your module, the Erl method will return the last defined line
number before the error was raised. E.g.,

1000:
On Error GoTo ErrHandler:
Debug.Print "Some Code Here"
1100:
Debug.Print "More Code Here"
Err.Raise 1
1200:
Exit Sub
ErrHandler:
Debug.Print Err.Description, Err.Source, Erl

In this example, Erl will return 1100, because 1100 is the last line number
encountered before the error was raised.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com ch...@cpearson.com

"Jos Vens" <jos....@planetinternet.be> wrote in message
news:B8385652.8D9%jos....@planetinternet.be...

jaf

unread,
Dec 9, 2001, 3:56:54 PM12/9/01
to
Hi Jos,
You can redefine a variable or string in each sub/function.
option explicit
dim vprocname as string

sub myfileopensub()
vprocname="fileopen"
code
end sub

sub main()
vprocname="main"
etc.


John


"Jos Vens" <jos....@planetinternet.be> wrote in message
news:B8385652.8D9%jos....@planetinternet.be...

Jos Vens

unread,
Dec 9, 2001, 4:45:13 PM12/9/01
to
Hi John

Yes, but that's just what I didn't want to do. I can also pass the
procedurename to my error function that handles it but then I always have to
retype it. If I rename one time the procedurename, I have to change the
variable too.
Wouldn't it be easy if microsoft made something like

Application.VBE.ActiveCodePane..CodeModule.Procedure in which it stored the
current procedurename
Application.VBE.ActiveCodePane.CodeModule.ProcLine in which it stored the
current procedureline in the module

Why is there something like

Application.VBE.ActiveCodePane.CodeModule in which microsoft stores the
current modulename??? And nothing for procedurename and line???

Thanks anyway,
I consider your suggestion
Jos

in article uzI$XQPgBHA.2204@tkmsftngp04, jaf at joh...@my.hotmail.com wrote
on 2001-12-09 21:56:

Jos Vens

unread,
Dec 9, 2001, 5:03:35 PM12/9/01
to
Hi Chip

The Erl method only returns the last label(numeric), not the last line
number. In combination with my general procedure, I can't use it I suppose?

Thanks anyway
Jos Vens

in article eCeHoNEgBHA.2072@tkmsftngp03, Chip Pearson at ch...@cpearson.com

0 new messages