有关在 Excel 中使用 VBA 的 Application.Caller 的更多信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11267597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
More Information about Application.Caller with VBA in Excel
提问by Ehudz
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.
我一直在我的代码中使用 Application.Caller 进行比较。当用户单击命令按钮时,我假设 Application.Caller 返回命令按钮的名称,但我不确定。
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?
我正在尝试执行以下操作:msgbox(Application.Caller),但意识到它不是正确的数据类型。我将如何弄清楚 Application.Caller 实际上是什么?
回答by Siddharth Rout
As shown in that link, Application.Caller
will not always be of String
type
如该链接所示,Application.Caller
并不总是属于String
类型
You are using StrComp
which compares 2 strings. I would recommend using this.
您正在使用StrComp
它比较 2 个字符串。我会推荐使用这个。
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