当Application.Caller只返回错误时,如何获取单击按钮的行号?

时间:2016-04-23 18:08:10

标签: excel vba excel-vba

像我这样的问题很多,我只是尝试了许多地方提到的解决方案,例如here。但对我来说,它只返回错误"运行时错误' 1004':无法获取工作表类的按钮属性"当我输入以下代码时:

Sub Mainscoresheet() 
     ' Mainlineup Macro
    Dim b As Object, RowNumber As Integer 
    Set b = ActiveSheet.Buttons(Application.Caller) 'here I get the error
    With b.TopLeftCell 
        RowNumber = .Row
    End With 
    MsgBox "Row Number " & RowNumber 
End Sub

有没有人知道另一种可以解决我的问题的解决方案? 如果您需要任何进一步的信息,请随时询问。 提前谢谢!

亲切的问候, 朱莉娅

1 个答案:

答案 0 :(得分:2)

我测试了你的代码。它适用于表单按钮,但不适用于ActiveX按钮。这可能是问题吗?