Adding selections and submenu items to the Budgeting menu : Menu « Application « VBA / Excel / Access / Word






Adding selections and submenu items to the Budgeting menu

 
Sub CreateMenu()
    Dim HelpMenu As CommandBarControl
    Dim NewMenu As CommandBarPopup

    Set HelpMenu = CommandBars(1).FindControl(ID:=30010)
    
    If HelpMenu Is Nothing Then
        Set NewMenu = CommandBars(1).Controls _
         .Add(Type:=msoControlPopup, temporary:=True)
    Else
        Set NewMenu = CommandBars(1).Controls _
         .Add(Type:=msoControlPopup, Before:=HelpMenu.Index, _
         temporary:=True)
    End If
    NewMenu.Caption = "&ItemMenu"
    Set MenuItem = NewMenu.Controls.Add _
      (Type:=msoControlButton)
    With MenuItem
        .Caption = "&Item1..."
        .FaceId = 162
        .OnAction = "Macro1"
    End With
    Set MenuItem = NewMenu.Controls.Add _
      (Type:=msoControlButton)
    With MenuItem
        .Caption = "&Item2..."
        .FaceId = 590
        .OnAction = "Macro2"
    End With
    Set MenuItem = NewMenu.Controls.Add _
      (Type:=msoControlPopup)
    With MenuItem
        .Caption = "Item &Charts"
        .BeginGroup = True
    End With
    Set SubMenuItem = MenuItem.Controls.Add _
      (Type:=msoControlButton)
    With SubMenuItem
        .Caption = "Item &Variance"
        .FaceId = 420
        .OnAction = "Macro3"
    End With
    Set SubMenuItem = MenuItem.Controls.Add _
      (Type:=msoControlButton)
    With SubMenuItem
        .Caption = "&Summary"
        .FaceId = 422
        .OnAction = "Macro4"
    End With
End Sub

 








Related examples in the same category

1.Creating a Menu Bar
2.Add a new menubar with toggle action
3.Controling a CommandBarControl's Visibility
4.Deletes a control tagged "MyMenu2"
5.Create Submenus
6.Adds button, combobox, text box and drop down to tools menu
7.List Menu Information
8.List ShortCut Menus
9.Adding and deleting menus automatically
10.Disabling or hiding menus
11.Working with checked menu items
12.Disabling a shortcut menu
13.Enables the shortcut menu when the workbook is closed.
14.Create a new menu bar that replaces the existing menu bar
15.Adding a menu: Take 1
16.Adding the Budgeting menu to Excel's main menu bar
17.Determined the Id property of the Help menu by executing the following statement:
18.Deleting a menu from a menu bar
19.Adding a selection to Excel's Tools menu
20.Deleting a menu item from the Tools menu
21.Adding a menu selection that features a shortcut key
22.Adding menu items to shortcut menus
23.Deleting menu items from shortcut menus
24.removes the Hide menu item from two shortcut menus: the one that appears when you right-click a row header and the one that appears for a column header.
25.Disabling shortcut menu items
26.Disabling shortcut menus
27.If you want to disable all shortcut menus, use the following procedure:
28.Resetting shortcut menus: The Reset method restores a shortcut menu to its original condition.
29.Creating an entirely new and separate shortcut menu
30.Adding a new item to the Cell shortcut menu
31.Create a popup menu