2

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?

4

1 回答 1

7

如该链接所示,Application.Caller并不总是String类型

您正在使用StrCompwhich 比较 2 个字符串。我会推荐使用这个。

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

并将此宏分配给工作表上的表单按钮。

如果您看到我之前提供的链接中给出的示例,您会自动清楚:)

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
于 2012-06-29T19:29:28.943 回答