More than one level of sub menus under the menu item

B

Bryan44

I'm wanting to add more than just one level of submenus to my special menu
created for my new Excel application. I know how to do this:

Menu Item 1
Menu Item 2
|
-- Submenu Item 1
-- Submenu Item 2
...
-- Submenu Item N
Menu Item 3

and so on. What I want to be able to do is:

Menu Item 1
Menu Item 2
|
-- Submenu Item 1
|
-- SubSubmenu Item 1
-- SubSubmenu Item 2
|
-- SubSubSubMenu Item 1
-- Submenu Item 2
...
-- Submenu Item N
Menu Item 3

Now that might not make sense to the most casual observer but I've added
many levels of print functionality on my dictator application and it does
make sense for printing out a range of charts/worksheets or selected ones.

Anyone know how to do this in VBA?

Sincerely,

Bryan
 
B

Bob Phillips

Here is an example that append to the Tools menu

Sub MultiLevelMenus()
Dim oCb As CommandBar
Dim oCtl1 As CommandBarPopup
Dim oCtl2 As CommandBarPopup
Dim oCtl3 As CommandBarPopup
Dim oCtlBtn As CommandBarButton

Set oCb = Application.CommandBars("Worksheet Menu Bar")
With oCb
Set oCtl1 = .Controls("Tools").Controls.Add( _
Type:=msoControlPopup, _
temporary:=True)
oCtl1.Caption = "Level1"
With oCtl1
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton)
oCtlBtn.Caption = "Level1 Button1"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myLevel1Button1Macro"
With oCtl1
Set oCtl2 = .Controls.Add( _
Type:=msoControlPopup)
oCtl2.Caption = "Level2"
With oCtl2
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton)
oCtlBtn.Caption = "Level2 Button1"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myLevel2Button1Macro"
Set oCtl3 = .Controls.Add( _
Type:=msoControlPopup)
oCtl3.Caption = "Level3"
With oCtl3
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton)
oCtlBtn.Caption = "Level3 Button1"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myLevel3Button1Macro"
End With
End With
End With
'etc.
End With
End With
End Sub

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

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