capturing the Sub or Function name in the error message

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Is there a way VBA can capture the name of the Sub or Function in which it's
running? I realize you can type the name in as a string, but I'm getting
ready to add Error Trapping code to hundreds of procedures that currently do
not have any, and it would save a lot of time if VBA could capture it
programmatically.

Thanks in advance,

Paul
 
You can reduce typing/cut-paste a little by using a module-wide private
constant for the module/form/report name. Use the same constant name in each
module and then the error handler just needs the routine name added
manually. A simple CurrentProcedureName() function would have made error
handling a whole lot easier to implement.
 
www.mztools.com has a great (and free) addin that does a lot of this stuff
for you. You an enter your error handler to the procedure with a click of a
button, and include variables such as the procedure and module name.

Quite handy.

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
I just installed the mztools addin you suggested, Jack, and wow! - you're
right - you click a button and it installs the header and body as well as
the related commands and puts the module and procedure names in the error
handler's MsgBox title.

For the benefit of anyone else interested in using this, I'll mention that
although installation requires no more than double-clicking the downloaded
exe file, I spent a few moments trying to figure out where it was in order
to use it. It turns out it's in a submenu of the Tools menu in the VB
Editor called "MZ-Tools."

Thanks so much, Jack. You've saved me a lot of time and tedium.

Paul
 
Another great tool to make our development work easier and faster!

I wish I had known about this years ago, but better now than never.

Thanks, Doug.

P
 
Back
Top