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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
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.
 

Makrini

Well-known Member
Joined
May 22, 2007
Messages
1,035
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
 

mond007

New Member
Joined
Oct 9, 2008
Messages
34
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.
 

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127

ADVERTISEMENT

In the absence of other replies ..............................:)
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,295
Office Version
  1. 365
Platform
  1. Windows
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.:)
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,933
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,132,896
Messages
5,655,850
Members
418,247
Latest member
The_aze

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
Top