Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove custom menu code not working 1

Status
Not open for further replies.

ColdDay

Technical User
Nov 30, 2010
92
0
0
US
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:
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
I have checked my spelling and did not see any problems. There is no error message. It just does not work.

TIA.

Bill
 
Code:
[blue]Public Sub RemoveTSEmenu()
    Dim cbr As CommandBar
    
    On Error Resume Next
    
    Set cbr = [red][b]Application.[/b][/red]CommandBars("Worksheet Menu Bar")
    cbr.Controls("TSE Procedures").Delete
        
End Sub[/blue]

>There is no error message.

Well no, there wouldn't be thanks to:

[tt]On Error Resume Next[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top