submenus

D

Dimitri

Hello,

I have te following code to create a menu. In the first item i wanna have
some subitems. Can anyone tell me how to do this?

Sub Menu()
Dim Item As CommandBarControl
CustomizationContext = ActiveDocument.AttachedTemplate
CommandBars("Menu Bar").Controls.Add(msoControlPopup).Caption = "&Test"
With CommandBars("Menu Bar").Controls("Test").Controls
Set Item = .Add(Type:=msoControlButton)
Item.Caption = "MenuItem1"
Item.OnAction = "TestMacro"
Set Item = .Add(Type:=msoControlButton)
Item.Caption = "MenuItem2"
Item.OnAction = "TestMacro"
Set Item = .Add(Type:=msoControlButton)
Item.Caption = "MenuItem3"
Item.OnAction = "TestMacro"
Set Item = .Add(Type:=msoControlButton)
Item.Caption = "MenuItem4"
Item.OnAction = "TestMacro"
End With
End Sub

Thanks
Dimitri
 
D

Dimitri

Hello Brian,

Your link is for Excel. In wordt this seems not to be working. do you have
some code for Word?

thnaks Dimitri
 
D

Dimitri

Hello Brian,

got it woking in word but still a problem Just one subitem is create wen i
use serveral (always the last entry is shown)

do you know the way to use more than one entry?
 
D

Dimitri

Well I did some more trial and Error and see the result.

Sub Menu()
Dim Item As CommandBarControl
Dim subitem As CommandBarControl
CustomizationContext = ActiveDocument.AttachedTemplate
CommandBars("Menu Bar").Controls.Add(msoControlPopup).Caption = "&Dimitri"
With CommandBars("Menu Bar").Controls("Dimitri").Controls
Set Item = .Add(Type:=msoControlPopup)
Item.Caption = "MenuItem1"
With CommandBars("Menu
Bar").Controls("Dimitri").Controls("MenuItem1").Controls
Set Item = .Add(Type:=msoControlButton)
Item.Caption = "MenuItem1A"
Item.OnAction = "TestMacro"
Set Item = .Add(Type:=msoControlButton)
Item.Caption = "MenuItem1B"
Item.OnAction = "TestMacro"
End With
Set Item = .Add(Type:=msoControlButton)
Item.Caption = "MenuItem2"
Item.OnAction = "TestMacro"
Set Item = .Add(Type:=msoControlButton)
Item.Caption = "MenuItem3"
Item.OnAction = "TestMacro"
Set Item = .Add(Type:=msoControlButton)
Item.Caption = "MenuItem4"
Item.OnAction = "TestMacro"
End With
End Sub
 
B

Brian

Hi Dimitri,

Having a fun Lunch break with this. I've never tried it before. Tried some
of the things you did, but I am trying to figure out the use of the
BeginGroup in the object Brower. I think that may be the key.

Sorry I have no update at the moment
 

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