Hello, Basically I want to access an existing menu to add (sub)menu item: e.g. to access File CommandBarControl.
Set fileCtrl = Application.CommandBars("Menu Bar").Controls(1) 'File menu
But how do I get a reference to the other elements in the menu:
Set newCtrl = fileCtrl.Controls(1)
As far as I understood if CommandBarControl is of type msoControlPopup(CommandBarPopup) then this CommandBarControl has a Controls property. But I can't get anything going in this respect. There doesn't seem to exist a Controls property.
Any help welcome here!!!
==================================
By the way I found excel code that does something similar with the Help menu. It works ok in powerpoint but I am puzzled that it DOES work
:
Sub Autpen()
Dim lngPos As Long
Dim objHelpMenu As CommandBar
Dim objHelpMenuItem As CommandBarControl
Dim objExcelAbout As CommandBarControl
'Get reference to Help menu
Set objHelpMenu = Application.CommandBars("Help")
'???>> how come Help being a CommandBar????????????????????????? when I check each control type on the menubar I get returned type number 10:msoControlPopup<<'
'Determine the position of "About Microsoft Office Powerpoint"
Set objExcelAbout = objHelpMenu.Controls("About Microsoft Office Powerpoint")
If Not objExcelAbout Is Nothing Then
lngPos = objExcelAbout.Index
Else
lngPos = objHelpMenu.Controls.Count
End If
'add "myItemGoesHere"menu item
Set objHelpMenuItem = objHelpMenu.Controls.Add(msoControlButton, 1, , _
lngPos, True)
objHelpMenuItem.Caption = "myItemGoesHere"
objHelpMenuItem.BeginGroup = True
exit sub
Set fileCtrl = Application.CommandBars("Menu Bar").Controls(1) 'File menu
But how do I get a reference to the other elements in the menu:
Set newCtrl = fileCtrl.Controls(1)
As far as I understood if CommandBarControl is of type msoControlPopup(CommandBarPopup) then this CommandBarControl has a Controls property. But I can't get anything going in this respect. There doesn't seem to exist a Controls property.
Any help welcome here!!!
==================================
By the way I found excel code that does something similar with the Help menu. It works ok in powerpoint but I am puzzled that it DOES work
:
Sub Autpen()
Dim lngPos As Long
Dim objHelpMenu As CommandBar
Dim objHelpMenuItem As CommandBarControl
Dim objExcelAbout As CommandBarControl
'Get reference to Help menu
Set objHelpMenu = Application.CommandBars("Help")
'???>> how come Help being a CommandBar????????????????????????? when I check each control type on the menubar I get returned type number 10:msoControlPopup<<'
'Determine the position of "About Microsoft Office Powerpoint"
Set objExcelAbout = objHelpMenu.Controls("About Microsoft Office Powerpoint")
If Not objExcelAbout Is Nothing Then
lngPos = objExcelAbout.Index
Else
lngPos = objHelpMenu.Controls.Count
End If
'add "myItemGoesHere"menu item
Set objHelpMenuItem = objHelpMenu.Controls.Add(msoControlButton, 1, , _
lngPos, True)
objHelpMenuItem.Caption = "myItemGoesHere"
objHelpMenuItem.BeginGroup = True
exit sub