Breaking Items into Groups

When you get a menu with several items, it may help to break them into logical groups. To add a line between a set of menu items, you go to the first menu item below the line and specify that the BeginGroup property for this item is True. The following code creates a menu with a group line between the third and fourth menu item, as shown in Figure 24.3:

Sub CreateGroupedMenu()

Dim MenuObject As CommandBarPopup Dim Menultem 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 Menultem = MenuObject.Controls.Add(Type:=msoControlButton) Menultem.OnAction = "ImportData" Menultem.Caption = "&Import Data"

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

Set MenuItem = MenuObject.Controls.Add(Type:=msoControlButton) MenuItem.OnAction = "ProduceReport" MenuItem.Caption = "&Report"

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

Figure 24.3

Use the BeginGroup property to add horizontal bars between groups of menu items.The About item has its BeginGroup property set to True.

Figure 24.3

Use the BeginGroup property to add horizontal bars between groups of menu items.The About item has its BeginGroup property set to True.

0 0

Post a comment