K
kraljb
I have a macro that adds a menu button to excel, but it has bee
erroring out now. Here is the code that is being effected:
Private Sub Workbook_Open()
Dim MenuName as CommandBarButton
Dim ButtonName as CommandBarPopup
If Not CheckMenu("MenuName") Then
Set ButtonName = Application.CommandBars("Worksheet Men
Bar").Controls.Add(msoControlPopup, , , , True)
ButtonName.Caption = "MenuN&ame"
Else
Set ButtonName = Application.CommandBars("Worksheet Men
Bar").Controls.Item("MenuName")
End If
Set MenuName = ButtonName.Controls.Add(msoControlButton, , , , True)
MenuName.caption = "Report1"
MenuName.OnAction = "RunReport1"
MenuName.BeginGroup = True
End Sub
Function CheckMenu(caption As String) As Boolean
Dim ButtonName as CommandBarPopup
-On Error GoTo nomenu-
CheckMenu = False
*Set ButtonName = Application.CommandBars("Worksheet Men
Bar").Controls.Item(caption)*
CheckMenu = True
-nomenu:-
End Function
The error is occuring on the *bold* line. I am not very good with code
but shouldn't the Invalid procedure or argument be handled with th
error handler -Italics-.
What I do not understand at all is that it was working, and now it i
not, but there has been no change to the code. Although there was a
upgrade to a proprietary software happening when the change occured
Could this be related to that, or just a fluke?
Thank you in advance,
Joh
erroring out now. Here is the code that is being effected:
Private Sub Workbook_Open()
Dim MenuName as CommandBarButton
Dim ButtonName as CommandBarPopup
If Not CheckMenu("MenuName") Then
Set ButtonName = Application.CommandBars("Worksheet Men
Bar").Controls.Add(msoControlPopup, , , , True)
ButtonName.Caption = "MenuN&ame"
Else
Set ButtonName = Application.CommandBars("Worksheet Men
Bar").Controls.Item("MenuName")
End If
Set MenuName = ButtonName.Controls.Add(msoControlButton, , , , True)
MenuName.caption = "Report1"
MenuName.OnAction = "RunReport1"
MenuName.BeginGroup = True
End Sub
Function CheckMenu(caption As String) As Boolean
Dim ButtonName as CommandBarPopup
-On Error GoTo nomenu-
CheckMenu = False
*Set ButtonName = Application.CommandBars("Worksheet Men
Bar").Controls.Item(caption)*
CheckMenu = True
-nomenu:-
End Function
The error is occuring on the *bold* line. I am not very good with code
but shouldn't the Invalid procedure or argument be handled with th
error handler -Italics-.
What I do not understand at all is that it was working, and now it i
not, but there has been no change to the code. Although there was a
upgrade to a proprietary software happening when the change occured
Could this be related to that, or just a fluke?
Thank you in advance,
Joh