PDA

View Full Version : Solved: Identify the Macro That Called Another Macro



Cyberdude
12-09-2008, 03:55 PM
Hey, Malik641, I enjoyed your education on determining which button called a macro. (conversation with OlderDaze).
Now I?m wondering if you can produce a technique for determining a caller macro?s name. I?ve always wanted a method for determining in an executing macro what the name is of the macro that called it. Surely that info is recorded somewhere (isn?t it??). :dunno

Bob Phillips
12-09-2008, 05:28 PM
No it isn't, you need to save the value yourself and pick it up. In my code I build a caller stack using an array, popping the name onto the stack on entry, and off on exit.

Kenneth Hobs
12-10-2008, 07:37 AM
A Public variable could be used for the method that xld explained.

Another method is to pass a parameter. e.g.
Sub test()
hi
hi "The Test Sub played the Sub hi."
End Sub

Sub hi(Optional macName As String)
If macName <> vbNullString Then
MsgBox macName
Exit Sub
End If
MsgBox "hi"
End Sub

Dr.K
12-10-2008, 09:39 AM
I've always passed a parameter, but I like XLD's solution better. Thanks!

One nice thing about parameter passing, is that sometimes you can use it to build your whole error messge, which is then displayed by the error trap in the called procedure.