Create menus and sub menus with VBA

A

aehan

I need to create menus with sub menus in VBA for a Ppt Addin. I can create
the menus, but the sub menus have me stumped (I'm quite new to all this). I
have the following code, which creates a sub menu, but the second sub menu
attaches itself to the first sub menu rather than to the main menu!! Can
someone help me please?
Thanks
Aehan

Dim myMainMenuBar As CommandBar
Dim iHelpMenu As Integer
Dim myCustomMenu As CommandBarControl

On Error Resume Next
Application.CommandBars.ActiveMenuBar.Controls("&Logos").Delete
On Error GoTo 0

Set myMainMenuBar = Application.CommandBars.ActiveMenuBar

iHelpMenu = myMainMenuBar.Controls("Help").Index

Set myCustomMenu = myMainMenuBar.Controls.Add(Type:=msoControlPopup, _
before:=iHelpMenu)

myCustomMenu.Caption = "&Logos"

Set myCustomMenu = myCustomMenu.Controls.Add(Type:=msoControlPopup)
myCustomMenu.Caption = "&Insert Logos"

With myCustomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Red on Black"
.OnAction = "TestMacro"
End With
With myCustomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "Red on White"
.OnAction = "TestMacro"
End With

Set myCustomMenu = myCustomMenu.Controls.Add(Type:=msoControlPopup)
myCustomMenu.Caption = "&Size Logos"

With myCustomMenu.Controls.Add(Type:=msoControlButton)
.Caption = "40"
.OnAction = "TestMacro"
End With
 
A

aehan

Thank you so much. I did try adding a new variable myself, but I added it
for the "Size Logos" control and of course it didn't work and I got an error
message!!! Some day I'll get my head round this properly, meantime I'm very
grateful to you for pointing out what I should do in a way that I can
understand.

Rgds
Aehan
 

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