View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
[email protected] paul.robinson@it-tallaght.ie is offline
external usenet poster
 
Posts: 789
Default Help reqd with adding menu items!!

Hi

Put this at the top of your code:

Set myMenuBar = CommandBars("Worksheet Menu Bar")
'If Excel crashed while last opened so that Before_Close() event
didn't happen
'the Timetable menubar may still exist. So delete it just in case
On Error Resume Next
myMenuBar.Controls("Tools").Delete
On Error GoTo 0

In the same module you also want this sub:

Public Sub Remove_Tools()
Dim myMenuBar As CommandBar

On Error Resume Next 'Incase it has already been deleted
Set myMenuBar = CommandBars("Worksheet Menu Bar")
cbWSMenuBar.Controls("Tools").Delete
End Sub
In the ThisWorkBook code module you want:

Private Sub Workbook_Open()
Call Test
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Msg As String
Dim Ans As Variant
'If section stops Tools being deleted if Cancel is clicked on File
Close message box
If Not Me.Saved Then
Msg = "Do you want to save the changes you made to "
Msg = Msg & Me.Name & "?"
Ans = MsgBox(Msg, vbQuestion + vbYesNoCancel)
Select Case Ans
Case vbYes
Me.Save
Case vbNo
Me.Saved = True
Case vbCancel
Cancel = True
Exit Sub
End Select
End If
Call Remove_Tools
End Sub

If you go to close the file, then cancel that close, your menu will
disappear. The code in the before close above stops that (code due to
John Wolfenbach I think)
There is also code in there to deal with the case where Excel might
crash and the close event cannot delete the menu.

regards
Paul