本文介绍了有关在Excel中使用VBA的Application.Caller的更多信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在代码比较中我一直在使用Application.Caller.当用户单击命令按钮时,我假设Application.Caller返回了命令按钮的名称,但不确定.

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.

我正在尝试执行以下操作:msgbox(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?

推荐答案

如该链接Application.Caller并不总是为String类型

您正在使用StrComp来比较2个字符串.我建议使用这个.

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

这篇关于有关在Excel中使用VBA的Application.Caller的更多信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 08:27