Getting Function name of the function currently running in VBA

  • Thread starter Thread starter JR
  • Start date Start date
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
 
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...
 
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...
 
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.
 
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.
 
Back
Top