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.
 

Some videos you may like

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

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
In the absence of other replies ..............................:)
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,530
Office Version
365
Platform
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
34,793
Office Version
365, 2019, 2016, 2010
Platform
Windows, 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,095,201
Messages
5,442,996
Members
405,212
Latest member
Arnie58

This Week's Hot Topics

  • Copy entire row if CountA <>0 to another sheet
    [B]I want to copy entire row if CountA <>0 for column J7:AM7 (headers on J6:AM6) and so on till the last used cell is column D and paste the...
  • Select last used Row in Table
    I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which...
  • excel workbook: do not allow certain file name
    Hello all, Don't think this has ever been asked before, but how do I restrict file save [Before_Save Event] if the name of the file being saved...
  • fixing problem autofilter
    hello i need help about my code when i search by code in textbox it doesn't show anything this is my data [ATTACH type="full"...
  • “Weight”
    Hi, i’ve got a long sheet filled with weights such as kg,g,L & ml. i can build a formula to convert kg into g and liter into ml. How ever, my...
  • How to capitalize everything before a certain character?
    In column A, I have some text: Hello good day.mp3 Hello good day.flac etc. I'd like to capitalize everything before the period. I don't need the...
Top