I am using an xla
file to run my vba-code in excel. I have many templates, which use this xla
file. Is there any way to find which template runs(opens) the xla
file from xla
.
I have used:
ThisWorkbook.FullName
but it returns the name of the xla
file and not the name of the template
I don't think there is a straightforward way for a Function
or a Sub
to find out who's calling it (because the call/stack tracing is not available programatically to VBA).
You could do your own tracing, by implementing some push
and pop
operations on a custom-made stack globally accessible in your .xla
, for example. When a function is called, it pushes its filename+module+name to the stack, and when it ends it pops that information from the stack.
But then again, it depends on the "benevolence" of the calling function (eg the one from the file that references your .xla
file) to use your tracing convention. Also, it might make your code more brittle. And also, it could make it worse actually, if you don't handle every exception that might break the execution of your functions/subs.
See also this (last section): http://www.cpearson.com/excel/DebuggingVBA.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.