Home » excel » excel vba – Run Time Error '91'

excel vba – Run Time Error '91'

Posted by: admin May 14, 2020 Leave a comment


Run Time Error ’91’ : Object Variable or With Block not Set

My code is

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

Please help me to resolve this error.

How to&Answers:

You have put Standard instead of "Standard". And hence I always suggest to use Option Explicit.

If you don’t use the " then Standard is treated as a variable.