Results 1 to 1 of 1

Thread: Application.Caller

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member Transformer's Avatar
    Join Date
    Mar 2012
    Posts
    91
    Rep Power
    13

    Lightbulb Application.Caller

    Application.Caller returns Range if VBA code is called from a Cell/Range.
    e.g. If a UDF(User Defined Function) is called from a Cell/Range and one wants to get the address of the Cell/Range ,where it is called from.
    Then it can be achieved using the following code and as in this case it returns Range so you can also set it to some object also.

    Code:
    Function Test()
        
        Dim objCaller      As Object '/Range
         
        Set objCaller = Application.Caller
        Debug.Print objCaller.Address '/Application.Caller.address
        Test = objCaller.Address
        
    End Function
    Application.Caller returns String if the caller is some control (e.g. DropDown,ListBox and CommandButton etc.) or Shape.

    e.g. if the following function is called from some shape/control then it will print and return shape/control's name.

    Code:
    Function ControlCaller()    
      
        Debug.Print Application.Caller
        ControlCaller= Application.Caller
        
    End Function
    Application.Caller returns Error if the caller is a VBA procedure or function.
    e.g if you call the above given function ControlCaller in some procedure or function then it will return an error.

    Code:
    Sub CallIt()    
      
        Call  ControlCaller()
        
    End Sub
    Note: Application.Caller does not work in Immediate Window
    Last edited by Transformer; 05-01-2013 at 02:48 PM.
    Regards,

    Transformer

Similar Threads

  1. VBA Trick of the Week :: Slicing an Array Without Loop - Application.Index
    By Transformer in forum Tips, Tricks & Downloads (No Questions)
    Replies: 0
    Last Post: 06-12-2013, 04:40 PM
  2. Add VBA Reference From Another Application Excel To PowerPoint
    By ds1001 in forum Rajan Verma's Corner
    Replies: 1
    Last Post: 06-02-2013, 02:43 PM
  3. Replies: 2
    Last Post: 12-04-2012, 02:05 PM
  4. Excel Application.OnKey With Parameter
    By Excel Fox in forum Excel Help
    Replies: 0
    Last Post: 11-29-2011, 01:31 PM
  5. Application.ScreenUpdating = False not working
    By LalitPandey87 in forum Excel Help
    Replies: 2
    Last Post: 11-08-2011, 08:55 AM

Posting Permissions

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