Working with a CommandBarMenuBar

You can use the CommandBarMenuBar to put menus on the CommandBar. The CommandBarMenuBar stores top-level menus in an Items collection. Each top-level menu is an Item. All Item objects, including top-level menus, have a SubItems collection to store other Item objects. In this way, a CommandBarMenuBar can support multiple levels of submenus.

The Item object supports two styles. To create a standard menu item, set the Style property to brMenuDefault. To create a menu separator, set Style to cbrMenuSeparator.

The following code example shows how to add a menu to a CommandBar.

Dim M as CommandBarMenuBar
Set M = CommandBar1.Controls.Add(cbrMenuBar)

Once you add the menu bar, you can add top-level menus and submenus.

Dim mnuFile
Set mnuFile = M.Items.Add (, "mnuFile", "File")
mnuFile.SubItems.Add , "nmuNew", "New"
mnuFile.SubItems.Add , "nmuOpen", "Open"
mnuFile.SubItems.Add , "nmuSave", "Save"

Then, in the MenuClick event, you can test the Key property to determine which menu is chosen by a user.