In the attached file TestFunc1 is a UDF called from the workbook. TestFunc1 calls UDF TestFunc2. TestFunc2 returns True of it is called by an Object, or False if not.
Why does TestFunc2 see its caller as an Object?
In the attached file TestFunc1 is a UDF called from the workbook. TestFunc1 calls UDF TestFunc2. TestFunc2 returns True of it is called by an Object, or False if not.
Why does TestFunc2 see its caller as an Object?
https://msdn.microsoft.com/en-us/lib...(v=vs.84).aspx
The expression argument can be any expression.
IsObject returns True if expression is a variable of Object subtype or a user-defined object; otherwise, it returns False.
The following example uses the IsObject function to determine if an identifier represents an object variable:
Dim MyInt, MyCheck, MyObject
Set MyObject = Me
MyCheck = IsObject(MyObject) ' Returns True.
MyCheck = IsObject(MyInt) ' Returns False.
deleted... not applicable. Application.Caller is returning an error though, so I don't think this works as you expect.
Please help by:
Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know
There are 10 kinds of people in this world... those who understand binary, and those who don't.
I'm not sure that I understand it any better. Application.Caller help file: https://msdn.microsoft.com/en-us/lib.../ff193687.aspx The thing that I find interesting in there is this:I note that the statement is how VBA was called, not how the specific procedure was called. So, my best explanation is that the spreadsheet calls the function (calls VBA) so the .caller property is set to the spreadsheet. Within this "instance" of VBA, the called procedure can call other procedures (which can also call other procedures), but the particular "instance" of VBA is still called by the .caller that called the original function.Originally Posted by MS VBA help
Originally Posted by shg
Thank you. I understand.
Problem is, I have several procedures written (incorrectly, as I now know) to interpret whether they've been called from a range or another procedure. That info allows for case-specific efficiencies in passing and returning arrays and array-like (i.e., range) data. Is there some other way of determining that info?
I'm sure there is -- I would not be surprised if there are many possibilities. This is also somewhat beyond my limited experience, so I am not sure all of the possible approaches or the pros and cons to them.
Taking a page from my mentor (who did all of his programming in FORTRAN), he would frequently include some kind of "called from" toggle in a procedure's argument list, and use that toggle to branch execution accordingly. Something like:You might research if and how VBA can access the "call stack" (this is the first stackoverflow result for my internet search for "can vba read call stack" http://stackoverflow.com/questions/1...lling-this-sub ). It doesn't look particularly promising that VBA can access the call stack at runtime, but such research might yield some ideas.![]()
Please Login or Register to view this content.
Thanks, again.
This isn't possible without passing a parameter as MrShorty describes.
Thanks for all the help. I'm going to resolve by passing optional argument like: Optional fromVBA as Boolean = FALSE
You could, at least, acknowledge the person on VBAExpress who suggested that.I'm going to resolve by ...
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks