3

I have been using Application.Caller in a comparison in my code. When a user clicks a commandbutton, I am assuming Application.Caller returns the name of the command button, but am unsure.

I am trying to do something like: msgbox(Application.Caller), but realized its not the right data type. How would I go figuring out what Application.Caller actually is?

Community
  • 1
  • 1
Ehudz
  • 613
  • 10
  • 22
  • 33
  • HTH http://msdn.microsoft.com/en-us/library/ff193687.aspx – Siddharth Rout Jun 29 '12 at 19:11
  • Hm...not quite sure I understand it completely. The comparison I'm doing is this: `If StrComp(Application.Caller, NodeSpanDict.Keys(i), 1) = 0` . Before it seemed to work...but now its not working when I try and get application.caller in a msgbox – Ehudz Jun 29 '12 at 19:19

1 Answers1

10

As shown in that link, Application.Caller will not always be of String type

You are using StrComp which compares 2 strings. I would recommend using this.

Sub Sample()
    If TypeName(Application.Caller) = "String" Then
        MsgBox StrComp(Application.Caller, "Button1")
    End If
End Sub

And assign this macro to the Form Button which you have on the worksheet.

If you see the example given in the link that I gave earlier, it automatically will be clear to you :)

Select Case TypeName(Application.Caller)
    Case "Range"
        v = Application.Caller.Address
    Case "String"
        v = Application.Caller
    Case "Error"
        v = "Error"
    Case Else
        v = "unknown"
End Select
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
  • Thanks Siddharth. I actually decided against using Application.Caller in favor of another variable I have which has the string of the form button clicked. I'll keep this in mind for the future though. Thanks for the clarification! – Ehudz Jun 29 '12 at 19:31