Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 07-04-2009, 03:50 PM
tryer tryer is offline
Valued Forum Contributor
 
Join Date: 16 Nov 2004
Posts: 204
tryer is becoming part of the community
Adding sub menu's

Please Register to Remove these Ads

I am using the code below which creates top level and second level menu items. What I would like to do is add third level menu items to this.
Can anyone help
Code:
   Set cbSubMenu = cbMenu.Controls.Add(msoControlPopup, 1, , , True)
    With cbSubMenu
        .Caption = "&Import/Export"
        .Tag = "SubMenu1"
        .BeginGroup = True
    End With

    ' add menuitem to submenu
    With cbSubMenu.Controls.Add(msoControlButton, 1, , , True)
        .Caption = "&Import file"
        .OnAction = "get_file"
        .Style = msoButtonIconAndCaption
        .FaceId = 71
        .State = msoButtonDown ' or msoButtonUp
    End With

    ' add menuitem to submenu
    With cbSubMenu.Controls.Add(msoControlButton, 1, , , True)
        .Caption = "&Export Data"
        .OnAction = "save_sheets_as_workbooks"
        .Style = msoButtonIconAndCaption
        .FaceId = 72
        .Enabled = True '
    End With
Reply With Quote
  #2  
Old 07-04-2009, 05:01 PM
Leith Ross's Avatar
Leith Ross Leith Ross is offline
Forum Moderator
 
Join Date: 15 Jan 2005
Location: San Francisco, Ca
MS Office Version:2000, 2003, & read 2007
Posts: 10,256
Leith Ross Has a higher level of understanding Leith Ross Has a higher level of understanding Leith Ross Has a higher level of understanding Leith Ross Has a higher level of understanding Leith Ross Has a higher level of understanding Leith Ross Has a higher level of understanding Leith Ross Has a higher level of understanding
Send a message via AIM to Leith Ross
Re: Adding sub menu's

Hello tryer,

The third menu must be a CommandBarPopup. Refer to Visual Basic help files under CommandBarPopup. There is simply too much information to repeat it all here.
__________________
Sincerely,
Leith Ross

Remember To Do the Following....

1. Use code tags. Place [code] before the first line of code and [/code] after the last line of code.
2. Thank those who have helped you by Clicking this Icon on the Gray Title Bar

3. Please mark your post [SOLVED] if it has been answered satisfactorily.


Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Reply With Quote
  #3  
Old 07-05-2009, 05:36 AM
buran buran is offline
Registered User
 
Join Date: 25 Jun 2009
Location: Sofia, Bulgaria
MS Office Version:Excel 2003, Excel 2007
Posts: 72
buran has an addiction to Excel
Re: Adding sub menu's

Here is an example from an add-in, I have made. Here I add MyMenu1 as a second level menu to MyMenu (in your case that's cbMenu). After that I add two buttons to this sub-menu. When you add msoControlButton for all the macros you want, you start adding msoControlButton again to the top level menu.

Code:
Set MyMenu1 = MyMenu.Controls.Add _
                  (Type:=msoControlPopup, Temporary:=True)
    MyMenu1.Caption = "Caption" 'Your caption here
    MyMenu1.BeginGroup = True


    Set newBtn = MyMenu1.Controls.Add(Type:=msoControlButton)
    With newBtn
        .Caption = "Caption1" 'Your caption here
        .FaceId = 230
        .Style = msoButtonIconAndCaption
        .OnAction = "Macro1" 'Your macro name here
    End With


    Set newBtn = MyMenu1.Controls.Add(Type:=msoControlButton)
    With newBtn
        .Caption = "Caption2" 'Your caption here
        .FaceId = 2019
        .Style = msoButtonIconAndCaption
        .OnAction = "Macro2" 'Your macro name here
    End With
Hope it will help. Of course you can change FaceId if you want different icon, or Style or BeginGroup property, according to your needs.
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump