Adding menus items to menus
Posted by Carl B on December 26, 2001 9:52 PM
I can add a menu to the menu bar, I can add menu items to that menu, I can add a menu as one of the items on that menu, I cannot add any menu items to the menu on that menu. Hope I didn't confuse anyone with that ( I confused myself)
This is what I have so far:
Private Sub Workbook_Open()
' Creates a new menu and adds menu items
Dim Cap(1 To 15)
Dim Mac(1 To 15)
Dim MenuName(1 To 15) As String
MenuName(1) = "About"
MenuName(2) = "&Update"
MenuName(3) = "Testing"
ActionName = "CommandButton1_Click"
Cap(1) = "Version 1.6"
Cap(2) = "Designed by "
Cap(3) = "For: "
Cap(4) = "Company Name"
Cap(5) = "Advance Timesheet One Pa&y Period"
Mac(1) = "CommandButton1_Click"
On Error Resume Next
' Delete the menu if it already exists
MenuBars(xlWorksheet).Menus(MenuName(1)).Delete
MenuBars(xlWorksheet).Menus(MenuName(2)).Delete
MenuBars(xlWorksheet).Menus(MenuName(3)).Delete
' Add the menus
' MenuBars(xlWorksheet).Menus.Add Caption:=MenuName(3)
MenuBars(xlWorksheet).Menus.Add Caption:=MenuName(2), Before:="Help"
MenuBars(xlWorksheet).Menus.Add Caption:=MenuName(1), Before:="Help"
' Add the menu items
With MenuBars(xlWorksheet).Menus(MenuName(1)).MenuItems
.Add Caption:=Cap(1)
.Add Caption:=Cap(2)
.Add Caption:=Cap(3)
.Add Caption:=Cap(4)
.AddMenu Caption:=MenuName(3)
End With
With MenuBars(xlWorksheet).Menus(MenuName(2)).MenuItems
.Add Caption:=Cap(5), OnAction:=Mac(1)
End With
End Sub