Getting Function name of the function currently running in VBA

J

JR

Anyway to retrieve the function name in the module the code is running
in.

I want to have an email sent to me in the error trap if there is a
failure and want it to send me the name of the function. I could just
type in the name in a text string, but I want to use this in a bunch of
modules and would rather have something generic like "
CurrentFunction.name"


i.e.
"An error occurred in module " & CurrentFunction.name

I was able to get the module name but not the function name.

ModuleName = Application.VBE.ActiveCodePanel.CodeModule


John
 
B

Baz

The only way is to hard code it unfortunately. However, if you use the
error handler add-in (in the Developer Tools i.e. not free!) you can create
a template which will put error handling code *including* the procedure name
into a procedure, or all the procedures in a module, with one click.

Unless someone else know about a similar, but free, add-in, of course...
 
J

JR

Thanks!

The only way is to hard code it unfortunately. However, if you use the
error handler add-in (in the Developer Tools i.e. not free!) you can create
a template which will put error handling code *including* the procedure name
into a procedure, or all the procedures in a module, with one click.

Unless someone else know about a similar, but free, add-in, of course...
 
D

Douglas J. Steele

Baz said:
The only way is to hard code it unfortunately. However, if you use the
error handler add-in (in the Developer Tools i.e. not free!) you can
create
a template which will put error handling code *including* the procedure
name
into a procedure, or all the procedures in a module, with one click.

Unless someone else know about a similar, but free, add-in, of course...

MZ-Tools http://www.mztools.com does that, plus much, much more.
 
J

JR

I have MZtool but wrote an error handler template program long before
Mztools came out. But Mztools adding of line numbers is a great tool
becasue you can then use the constant "ERL" to get the line number of
where the code broke and put that in your error handler message. Very
handy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top