Determine Calling Procedure Name in VBA

mond007

New Member
Joined
Oct 9, 2008
Messages
34
Hi,

I have a generic_error_hadler which I call on error and I setup quite a fancy msgbox with lots of details but one of the detail that I have to pass is the calling procedure name at run time i.e.

Code:
Sub Validation_Routine()
On Error GoTo Error_Handler
   valid = False
   If Range("first_name").Value = "" Then
        MsgBox "Please enter your name"
        Exit Sub
    End If
valid = True
Exit Sub
Error_Handler:
    Application.ScreenUpdating = True
    Call Generic_Handler(Err.Number, Err.Description, "Validation_Routine")
End Sub

I would like to call this Generic_Handler without having to setup or type the "Validation_Routine"

How can I get the calling procedure name ?

I have tried things like application.caller or
Application.VBE.... etc ut tono avail.

Thanks in Advance.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I often use a global variable that is set by each subroutine. Useful for debugging. eg:
Code:
Dim CurrentRoutine as String
 
Sub Validation_Routine()
    CurrentRoutine = "Validation"
' ...... etc.
 
Upvote 0
Wow - what a great idea Brian!

I assume you can then use "Watch" and see exactly what procedures have run in which order...

very nice
 
Upvote 0
Hi Guys,

I can appreciate the above but that does mean going into all subroutines and setting up

CurrentRoutine = "Validation" etc etc...

which is expensive on development time when you have several dozens of routines.

I wanted to do this automatically via some object that I can grab the routine name information from.

Thanks in advance.
 
Upvote 0
mond007

I'm sorry but as far as I know there is no way to do this easily.:)

This is a question often asked here, and I'm sure you could find some answers/workarounds if you tried a board search.

Mind you I would wonder why you want this.:eek:

There are plenty of debugging tools in the VBE.

PS It might be an idea to post the code you are having problems with.:)
 
Upvote 0
There is no such object, as there is no programmable access to the call stack. You have to provide the name yourself, I'm afraid.
 
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,103
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top