Subroutine introspection: Can a sub know what sub called it?

electrikmonk

New Member
Joined
Aug 1, 2012
Messages
1
In Excel VBA, if subroutine A calls subroutine B, is there a way for subroutine B to know that subroutine A was what called it? I mean this for run-time, so not talking about watch window. Application.caller seems to give info in calling VBA from Excel, not for info about a subroutine calling it (corrections are welcome.)

Thanks for any help you can give with this.

Rich
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I will step out on a limb here and based on my years of general programming (not just VBA), the answer is "No" unless you include some kind of indication as a parameter to subroutine B which routine called it. Some programming languages have this facility but usually it is implemented similarly to what I just described except hidden behind the language definition. The only thing that subroutine B might be able to use to determine who called is the return address that is pushed onto the procedure stack. But you would have to have knowledge about how compiled VBA is structured to get any meaningful information even if you could access the procedure stack from normal VBA. Better to explicitly pass a reference to subroutine B about who called.
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,314
Members
449,153
Latest member
JazzSingerNL

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