I have this code which adds one menu at the top of the worksheet and I want to add more. My current sheet has a large number of scripts liatsed under it for different purposes and I'd like to divide it into different menus.
many thanks
john
Const TopMenuName = "Virgin &Money Giving"
Public Sub Workbook_Open()
Dim iHelpMenu As Integer
Dim cmbBar As CommandBar
Dim cmbControl As CommandBarControl
On Error Resume Next
Set cmbBar = Application.CommandBars("Worksheet Menu Bar")
iHelpMenu = cmbBar.Controls("Help").Index
' delete if already there
For Each cmbControl In cmbBar.Controls
If cmbControl.Caption = TopMenuName Or TopMenuName2 Then
cmbBar.Controls(TopMenuName).Delete
End If
Next
Set cmbControl = cmbBar.Controls.Add(Type:=msoControlPopup, Before:=iHelpMenu, temporary:=True) 'adds a menu item to the Menu Bar
With cmbControl
.Caption = TopMenuName 'names the menu item
With .Controls.Add(Type:=msoControlButton) 'adds a dropdown button to the menu item
.Caption = "Process Payment File" 'adds a description to the menu item
.OnAction = "VirginMoney" 'runs the specified macro
.FaceId = 37 'assigns an icon to the dropdown
End With
End With
Range("A1").Select
End Sub
Public Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next 'in case the menu item has already been deleted
Application.CommandBars("Worksheet Menu Bar").Controls(TopMenuName).Delete 'delete the menu item
End Sub
Bookmarks