I want to add a custom menu when opening a wb and remove the menu when closing the wb. The open code works. The closing code does not. Here is what I have:
'following proc calls/creates the custom menu when this wb is opened. It works.
The following should delete the menu when the wb is closed. It does not delete the menu.
I have checked my spelling and did not see any problems. There is no error message. It just does not work.
TIA.
Bill
Code:
'Add a custom menu
Public Sub AddTSEMenu()
Dim cbr As CommandBar
Dim ctlMenu As CommandBarControl
'add new menu control
Set cbr = Application.CommandBars("Worksheet Menu Bar")
Set ctlMenu = cbr.Controls.Add(Type:=msoControlPopup)
'add controls to new menu. code for all in module 5.
With ctlMenu
.Caption = "TSE Procedures"
With .Controls.Add(Type:=msoControlButton)
.Caption = "Enter Time Sheets"
.OnAction = "aEnterTimesheetInfoSkipUnitsForStraightTime"
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "Create TIMSELS"
.OnAction = "aProcessIndividualBranchTimesheets"
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "Reset for Processing"
.OnAction = "aResetForProcessing"
End With
End With
End Sub
'following proc calls/creates the custom menu when this wb is opened. It works.
Code:
Private Sub Workbook_Open()
Call AddTSEMenu
End Sub
The following should delete the menu when the wb is closed. It does not delete the menu.
Code:
Public Sub RemoveTSEmenu()
Dim cbr As CommandBar
On Error Resume Next
Set cbr = CommandBars("Worksheet Menu Bar")
cbr.Controls("TSE Procedures").Delete
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call RemoveTSEmenu
End Sub
TIA.
Bill