A while back I posted a thread asking for help on creating an Excel menu bar using a macro when a particular spreadsheet was opened. The replies were very helpful and I have now managed to do this using menu items that have macros under them. The code under Workbook Open is as follows:
'Create new menu bar
Set brMyMenu = Application.CommandBars.Add(Name:="MyMenu", Position:=msoBarTop, MenuBar:=True, Temporary:=True)
With brMyMenu
'Add menu
Set cbpMyMenu = .Controls.Add(Type:=msoControlPopup)
With cbpMyMenu
.Caption = "&Options"
'Add Set menu item
Set cbbMymenu = .Controls.Add(Type:=msoControlButton)
With cbbMymenu
.Caption = "&Main Menu"
.FaceId = 18
.OnAction = "GoToMainMenu"
End With
'Add Set menu item
Set cbbMymenu = .Controls.Add(Type:=msoControlButton)
With cbbMymenu
.Caption = "&Set"
.FaceId = 18
.OnAction = "ReportSet"
End With
'Add Unset menu item
Set cbbMymenu = .Controls.Add(Type:=msoControlButton)
With cbbMymenu
.Caption = "&Unset"
.FaceId = 18
.OnAction = "ReportUnset"
End With
End With
'Make new menu visible (replace standard menu)
.Visible = True
End With
'Make toolbars invisible
Application.CommandBars("Standard"
.Visible = False
Application.CommandBars("Formatting"
.Visible = False
This creates a menu bar with three options under a single menu - Main Menu, Set and Unset. These all work by running other macros when they are selected. But does anyone know how to create normal menu items in the menu bar e.g. Print, Save As etc? When customising a menu bar manually these normal Excel commands can be dragged in but how are they added if the menu bar is being created using code?
'Create new menu bar
Set brMyMenu = Application.CommandBars.Add(Name:="MyMenu", Position:=msoBarTop, MenuBar:=True, Temporary:=True)
With brMyMenu
'Add menu
Set cbpMyMenu = .Controls.Add(Type:=msoControlPopup)
With cbpMyMenu
.Caption = "&Options"
'Add Set menu item
Set cbbMymenu = .Controls.Add(Type:=msoControlButton)
With cbbMymenu
.Caption = "&Main Menu"
.FaceId = 18
.OnAction = "GoToMainMenu"
End With
'Add Set menu item
Set cbbMymenu = .Controls.Add(Type:=msoControlButton)
With cbbMymenu
.Caption = "&Set"
.FaceId = 18
.OnAction = "ReportSet"
End With
'Add Unset menu item
Set cbbMymenu = .Controls.Add(Type:=msoControlButton)
With cbbMymenu
.Caption = "&Unset"
.FaceId = 18
.OnAction = "ReportUnset"
End With
End With
'Make new menu visible (replace standard menu)
.Visible = True
End With
'Make toolbars invisible
Application.CommandBars("Standard"
Application.CommandBars("Formatting"
This creates a menu bar with three options under a single menu - Main Menu, Set and Unset. These all work by running other macros when they are selected. But does anyone know how to create normal menu items in the menu bar e.g. Print, Save As etc? When customising a menu bar manually these normal Excel commands can be dragged in but how are they added if the menu bar is being created using code?