+ Reply to Thread
Results 1 to 10 of 10

UDF called by another UDF seel Caller as an Object

  1. #1
    Registered User
    Join Date
    09-03-2009
    Location
    Red Bank, NJ
    MS-Off Ver
    Excel 2010
    Posts
    55

    UDF called by another UDF seel 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?
    Attached Files Attached Files

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: UDF called by another UDF seel 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.

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: UDF called by another UDF seel Caller as an Object

    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.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: UDF called by another UDF seel Caller as an Object

    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:
    Quote Originally Posted by MS VBA help
    This property returns information about how Visual Basic was called [emphasis mine]
    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.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Registered User
    Join Date
    09-03-2009
    Location
    Red Bank, NJ
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: UDF called by another UDF seel Caller as an Object

    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?

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: UDF called by another UDF seel Caller as an Object

    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:
    Please Login or Register  to view this content.
    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.

  7. #7
    Registered User
    Join Date
    09-03-2009
    Location
    Red Bank, NJ
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: UDF called by another UDF seel Caller as an Object

    Thanks, again.

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: UDF called by another UDF seel Caller as an Object

    This isn't possible without passing a parameter as MrShorty describes.

  9. #9
    Registered User
    Join Date
    09-03-2009
    Location
    Red Bank, NJ
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: UDF called by another UDF seel Caller as an Object

    Thanks for all the help. I'm going to resolve by passing optional argument like: Optional fromVBA as Boolean = FALSE

  10. #10
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: UDF called by another UDF seel Caller as an Object

    I'm going to resolve by ...
    You could, at least, acknowledge the person on VBAExpress who suggested that.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. getting an error called Object required
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-08-2014, 06:53 AM
  2. Replies: 2
    Last Post: 01-21-2014, 09:42 PM
  3. Replies: 3
    Last Post: 03-29-2012, 01:58 PM
  4. App.Caller for CommandBarControl
    By foxguy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2011, 12:29 PM
  5. Exiting called macro on error, then ending macro caller.
    By Yappa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2008, 10:28 PM
  6. Goal Seel To get Average!?
    By Neo1 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-04-2006, 09:00 PM
  7. Row = Application.Caller.Row
    By Charles Woll in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-28-2005, 10:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1