Creating Menus and Sub Menus

P

Peter Rooney

I want to add a new item "SysMan" to the left of "Help" on the Menu Bar.

This should contain a number of commands (including "Save") and sub menus,
one of which is "Create" which will have six menu items.

Sub AA_InsertMenu()
Dim cmbNewMenu As CommandBar
Dim ctlPopup As CommandBarPopup

Set cmbNewMenu = Application.CommandBars("Menu Bar")

With cmbNewMenu.Controls
Set ctlPopup = .Add(Type:=msoControlPopup, Before:=9)
With ctlPopup
.Caption = "&SysMan"
With .Controls.Add
.Caption = "&Save"
End With
End With
End Sub

I run the above procedure, and it creates "SysMan" with a menu item "Save"
on the menu bar no problem.

I then run another procedure to add the "Create" sub menu items to Sysman

Sub AA_InsertSubMenu()

Dim cmbMenu As CommandBar
Dim ctlPopup As CommandBarPopup

<< Set cmbMenu = Application.CommandBars("SysMan")>>

Set ctlPopup = cmbMenu.Controls.Add(Type:=msoControlPopup)

With ctlPopup
.Caption = "&Create"

With .Controls.Add
.Caption = "1. Core Tools"
End With
With .Controls.Add
.Caption = "&2 Service Management"
End With
With .Controls.Add
.Caption = "&3 Software Management"
End With
With .Controls.Add
.Caption = "&4 Storage Management"
End With
With .Controls.Add
.Caption = "&5 General"
End With
With .Controls.Add
.Caption = "&6 CIS"
End With
End With
End Sub

but when I run the procedure, I get the following message:

Invalid procedure call or argument

against the line of code bounded by the << >> above.

However, if I substitute "Tools" for "Sysman" in the above procedure, I get
a perfectly created sub-menu added to the bottom of The tools menu.

What am I doing wrong?

Also, how do I attach a particular macro procedure to a menu command item
e.g. "1. Core Tools" as above?

I await your massive knowledge, oh mighty MVP ers!

Cheers

Pete
 
P

Peter Rooney

I give up! I realised that trying to achieve this in two seperate procedures
wasn't a very good way of going about it, so I tried to put it in one. I've
completely lost track of objects, properties and everything else, so I've
just put comments in my pseudocode - can ANYONE out there help me..?

Sub AA_InsertMenu()
Dim cmbNewMenu As CommandBar
Dim ctlPopup As CommandBarPopup

Application.CommandBars("Menu Bar").Reset
Set cmbNewMenu = Application.CommandBars("Menu Bar")
With cmbNewMenu.Controls
'---------------------------------
'Add "SysMan" menu to the Menu Bar
'---------------------------------
Set ctlPopup = .Add(Type:=msoControlPopup, Before:=9)
With ctlPopup
.Caption = "SysMan"
'----------------------------------------------------------
'Add "Print", "Save" and "Plan" menu items to "SysMan" menu
'----------------------------------------------------------
With .Controls.Add
.Caption = "Print"
End With
With .Controls.Add
.Caption = "Save"
End With
With .Controls.Add
.Caption = "Plan"
'---------------------------------------------------------
'Add 6 commands to the "Plan" submenu on the "SysMan" menu
'---------------------------------------------------------
With .Controls.Add
.Caption = "&1. Core Tools"
End With
With .Controls.Add
.Caption = "&2. Service Management"
End With
With .Controls.Add
.Caption = "&3. Software Management"
End With
With .Controls.Add
.Caption = "&4. Storage Management"
End With
With .Controls.Add
.Caption = "&5. General"
End With
With .Controls.Add
.Caption = "&6. CIS"
End With
End With
End With
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top