+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    314

    Adding sub menu's

    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

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,450

    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 the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    161

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0