More Information about Application.Caller with VBA in Excel

后端 未结 1 1777
春和景丽
春和景丽 2021-01-15 06:21

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,

相关标签:
1条回答
  • 2021-01-15 07:15

    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
    
    0 讨论(0)
提交回复
热议问题