how to know a caller at run-time
Hi Dudely,
Thank you very much! I like your secod idea since I can avoid a lots change
in code.
Clara
--
thank you so much for your help
"Dudely" wrote:
I think what you're asking is, can you determine from where a sub is
being called? In other words, who is the parent of this child that is
executing.
First I should point out, I'm no expert, so somebody else probably has
a better way. However, two ways I can think of a
1) If you're calling routines yourself, simply pass in that info. as
an argument to the called routine.
So for example if parent calls childA, then you'd have:
Sub Parent()
call childA ("Parent's Name")
end Sub
Then childA will know who called it.
2) If you're talking about a routine that executes based on an
interupt or callback, you could declare a global variable, and each
time you enter a new routine, you change the global to indicate the
name of the routine.
Something like...
Sub DoSomething_Click()
msgbox "I was called by", MyName ' prints last value of "MyName"
MyName="DoSomething_Click" ' update "MyName"
code....
end Sub
Stick that in every function you have. Not a perfect solution, but
better than nothing. Again, maybe someone else has a better idea, I'm
new to programming Excel and VBA.
Personally I just walk through the code, tracing one step at a time.
On Jun 4, 12:05 pm, clara wrote:
Hi all,
Is it possible to tell a caller in its callee sub? This question originates
from the following senario:
in the change event handler of a sheet, application.screenupdaing is set
true at the end of sub. there is a caller sub will cause the handler run
many times and do not hope the application.screenupdating restore to true in
the middle.
Clara
--
thank you so much for your help
|