borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (How to call Macro of Excel in VB6.0)Next Topic (Please Help- Need simple VB code (similar to Macro)) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : reference to submenu
Poster Message
Pete_R
Level: Trainee

Registered: 29-04-2006
Posts: 1

icon reference to submenu

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 Auto_Open()

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

30-04-2006 at 12:02 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : reference to submenu
Previous Topic (How to call Macro of Excel in VB6.0)Next Topic (Please Help- Need simple VB code (similar to Macro)) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder