Private Sub Workbook_Open()
Dim NumMacros As Integer
Dim cbar As CommandBar
Dim myControl As Object
NumMacros = 1 'Number of macros to go in menu
'Checks to see if command bar exists
For Each cbar In CommandBars
If cbar.Name = "Custom Menu" Then
MsgBox "Custom Menu already exists."
Exit Sub
End If
Next
'Creates command bar
Set cbar = CommandBars.Add(Name:="Custom Menu", Position:=msoBarFloating)
cbar.Visible = True
'Loop this until you add all your macros to the new command bar
While NumMacros <> 0
Set myControl = Application.CommandBars("Custom Menu").Controls.Add(Type:=msoControlButton, ID:=2950, Before:=1)
With myControl
.Caption = "Run Macro" 'Sets the caption
.FaceId = 2950 'Sets the icon
.OnAction = "Macro" 'Set which macro will run
.Style = msoButtonAutomatic 'Use either of the following to replace 'msoButtonAutomatic' for either caption only or icon only: 'msoButtonCaption 'msoButtonIcon
End With
NumMacros = NumMacros - 1
Wend
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim cbar As CommandBar
'Deletes the custom command bar
For Each cbar In CommandBars
If cbar.Name = "Custom Menu" Then
cbar.Delete
End If
Next
End Sub