Below is the code I currently have. I don't get any errors but nothing happens (that I can see anyway)
Pretty sure the code is running because I was getting an error in beforeclose until I add the On Error Resume Next
Running Excel 2016
Thanks in advance
Pretty sure the code is running because I was getting an error in beforeclose until I add the On Error Resume Next
Running Excel 2016
Thanks in advance
Code:
Private Sub Workbook_Open()
Dim mymenubar As CommandBar
Dim newmenu As CommandBarPopup
Dim ctrl1, ctrl2 As CommandBarButton
On Error Resume Next
Set mymenubar = Application.CommandBars("Worksheet menu Bar")
Set newmenu = mymenubar.Controls.Add(Type:=msoControlPopup, Temporary:=True, before:=2)
newmenu.Caption = "SetBilder"
Set ctrl1 = newmenu.Controls.Add(Type:=msoControlButton, ID:=1)
With ctrl1
.Caption = "Print All"
.Style = msoButtonCaption
.OnAction = "'" & ThisWorkbook.Name & "'!printall"
End With
Set ctrl2 = newmenu.Controls.Add(Type:=msoControlButton, ID:=1)
With ctrl2
.Caption = "Print No Cost"
.Style = msoButtonCaption
.OnAction = "'" & ThisWorkbook.Name & "'!printnocost"
End With
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim CmdBar As CommandBar
Dim CmdBarMenu As CommandBarControl
Set CmdBar = Application.CommandBars("Worksheet Menu Bar")
Set CmdBarMenu = CmdBar.Controls("SetBilder")
CmdBarMenu.Delete
End Sub
Last edited by a moderator: