Adding a Flyout Menu

You can reasonably fit 12 items on a typical menu. When you get beyond that number, it makes sense to group several menu items as subitems under a single menu heading. In Figure 24.1, the Reports Center menu item leads to a fly-out menu with many reports.

This is relatively simple to set up. The Reports Center menu item is a control of type msoControlPopup. After this is defined, then you can define many submenu items to the Reports Center menu item.

You define menu items in order, setting up the Report Center menu item, then the submenu items for Reports, then the Graph Center menu item, then the submenu items for Graphs, and so on. The following code produces the menu shown in Figure 24.4:

Sub CreateFullMenu()

Dim MenuObject As CommandBarPopup Dim MenuItem As Object Dim SubMenuItem As Object

' Make sure the menus aren't duplicated Call DeleteMenu

Set MenuObject = Application.CommandBars(l). _ Controls.Add(Type:=msoControlPopup, _ Before:=10, temporary:=True) MenuObject.Caption = "&XYZ Co"

Set MenuItem = MenuObject.Controls.Add(Type:=msoControlButton) MenuItem.OnAction = "ImportData" MenuItem.Caption = "&Import Data"

Set MenuItem = MenuObject.Controls.Add(Type:=msoControlButton) MenuItem.OnAction = "ExportData" MenuItem.Caption = "&Export Data"

Set MenuItem = MenuObject.Controls.Add(Type:=msoControlPopup) MenuItem.Caption = "&Reports Center" MenuItem.BeginGroup = True

Set SubMenultem = MenuItem.Controls.Add(Type:=msoControlButton) SubMenultem.OnAction = "StyleRptNew" SubMenuItem.Caption = "St&yle Report"

Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton) SubMenuItem.OnAction = "CategoryRptNew" SubMenuItem.Caption = "Category Repor&t"

Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton) SubMenuItem.OnAction = "ReportCard" SubMenuItem.Caption = "Report Card"

Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton) SubMenuItem.OnAction = "OverRpt" SubMenuItem.Caption = "Long term styles report" SubMenuItem.BeginGroup = True

Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton) SubMenuItem.OnAction = "CreateReportCard" SubMenuItem.Caption = "Store Status"

Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton) SubMenuItem.OnAction = "InventoryAgingReportNew" SubMenuItem.Caption = "Inventory Aging" SubMenuItem.BeginGroup = True

Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton) SubMenuItem.OnAction = "ShowStockReport" SubMenuItem.Caption = "Stock at Risk"

Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton) SubMenuItem.OnAction = "ShowRecTransfer" SubMenuItem.Caption = "Recommended Transfers"

Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton) SubMenuItem.OnAction = "ShowSummaryNew" SubMenuItem.Caption = "Summary Report"

Set MenuItem = MenuObject.Controls.Add(Type:=msoControlPopup) MenuItem.Caption = "Graphs Center"

Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton) SubMenuItem.OnAction = "GraphOne" SubMenuItem.Caption = "&Sales Graph"

Set SubMenuItem = MenuItem.Controls.Add(Type:=msoControlButton) SubMenuItem.OnAction = "GraphTwo" SubMenuItem.Caption = "&Inventory Graph"

Set MenuItem = MenuObject.Controls.Add(Type:=msoControlButton) MenuItem.OnAction = "AboutMe" MenuItem.Caption = "Abou&t Program" MenuItem.BeginGroup = True End Sub

0 0

Post a comment