2012-09-28 125 views
1

运行时错误 '91':对象变量或With块不设置运行时错误 '91'

我的代码是

Private Sub Workbook_Open() 
    Dim MenuBar As CommandBarButton 
    Set MenuBar = CommandBars(Standard).Controls(3) 
    MsgBox MenuBar.Caption 
End Sub 

请帮我解决这个错误。

+1

看不清你是如何得到这些的。应该是'错误9:下标超出范围'。 – GSerg

回答

3

您已将Standard而不是"Standard"。因此我总是建议使用Option Explicit

如果您不使用"那么Standard被视为一个变量。

+0

用于传播'Option Explicit.'的+1 – enderland