Consulting

Results 1 to 11 of 11

Thread: Create custom submenu using commandbar

  1. #1
    VBAX Regular
    Joined
    Jan 2012
    Posts
    7
    Location

    Create custom submenu using commandbar

    Hi All Gurus,

    I want to know on how to add submenu into custom menu we already have.

    My code is just like this :

    [VBA]
    Sub AddMenus()
    Dim cMenu1 As CommandBarControl
    Dim cbMainMenuBar As CommandBar
    Dim cbcCutomMenu As CommandBarControl

    Set cbMainMenuBar = Application.CommandBars("Worksheet Menu Bar")
    Set cbcCutomMenu = cbMainMenuBar.Controls.Add(Type:=msoControlPopup)

    cbcCutomMenu.Caption = "&New Menu"

    With cbcCutomMenu.Controls.Add(Type:=msoControlButton)
    .Caption = "Menu 1"
    .OnAction = "MyMacro1"
    End With

    With cbcCutomMenu.Controls.Add(Type:=msoControlButton)
    .Caption = "Menu 2"
    .OnAction = "MyMacro2"
    End With
    End Sub
    [/VBA]

    Lets say i want to give additional submenu on Menu 1, how i can do it?

    Please help me to solve this one...a lot of thank you before

  2. #2
    VBAX Tutor mohanvijay's Avatar
    Joined
    Aug 2010
    Location
    MADURAI
    Posts
    268
    Location
    Little example

    [vba]
    Dim Ma_Po As CommandBarPopup
    Dim Su_Po As CommandBarPopup
    Dim Su_Bu As CommandBarButton
    Dim Su_Bu2 As CommandBarButton

    Set Ma_Po = Application.CommandBars(1).Controls.Add(msoControlPopup)
    Ma_Po.Caption = "&New Menu"
    Set Su_Po = Ma_Po.Controls.Add(msoControlPopup)
    Su_Po.Caption = "Menu 1 pop up"
    Set Su_Bu = Su_Po.Controls.Add(msoControlButton)
    Su_Bu.Caption = "Sub Menu 1"
    Set Su_Bu2 = Ma_Po.Controls.Add(msoControlButton)
    Su_Bu2.Caption = "Menu 2"
    [/vba]

  3. #3
    VBAX Regular
    Joined
    Jan 2012
    Posts
    7
    Location

    Thumbs up

    Great It works !!

    Thank you so much

  4. #4
    VBAX Regular
    Joined
    Jan 2012
    Posts
    7
    Location
    Just a quick question, is that possible to give Faceid to msoControlPopup?

    It return an error when i tried this :
    Ma_Po.Controls.faceid = 582

    Thanks

  5. #5
    VBAX Regular
    Joined
    Jan 2012
    Posts
    7
    Location
    Sorry, i mean : Su_Po.faceid = xxx

    This code return an error.

    Thanks before..

    Quote Originally Posted by mohanvijay
    Little example

    [vba]
    Dim Ma_Po As CommandBarPopup
    Dim Su_Po As CommandBarPopup
    Dim Su_Bu As CommandBarButton
    Dim Su_Bu2 As CommandBarButton

    Set Ma_Po = Application.CommandBars(1).Controls.Add(msoControlPopup)
    Ma_Po.Caption = "&New Menu"
    Set Su_Po = Ma_Po.Controls.Add(msoControlPopup)
    Su_Po.Caption = "Menu 1 pop up"
    Set Su_Bu = Su_Po.Controls.Add(msoControlButton)
    Su_Bu.Caption = "Sub Menu 1"
    Set Su_Bu2 = Ma_Po.Controls.Add(msoControlButton)
    Su_Bu2.Caption = "Menu 2"
    [/vba]

  6. #6
    VBAX Tutor mohanvijay's Avatar
    Joined
    Aug 2010
    Location
    MADURAI
    Posts
    268
    Location
    commandbarpopup object does not have a Faceid property while commandbarbutton object does

    see the all the methods and properties of these objects in object browser

  7. #7
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    j321ry,
    Welcome to the forum.

    I'm glad you found help, but I remind you that you agreed to post a link when you cross post a question.

    Why cross posting is an issue and how to do it is explained here. LINK

    cross posted at:
    http://www.ozgrid.com/forum/showthread.php?t=161141

  8. #8
    VBAX Regular
    Joined
    Jan 2012
    Posts
    7
    Location
    Hi mohanvijay many thanks for your quick reply..

    Quote Originally Posted by mohanvijay
    commandbarpopup object does not have a Faceid property while commandbarbutton object does

    see the all the methods and properties of these objects in object browser

  9. #9
    VBAX Regular
    Joined
    Jan 2012
    Posts
    7
    Location
    Hi mikerickson,

    I'm sorry about that, next time i do cross post a question i will post the link as well. i'm a very newbie for this and just want to get a quick response from our expert.

    Thanks for reminds me..

    Quote Originally Posted by mikerickson
    j321ry,
    Welcome to the forum.

    I'm glad you found help, but I remind you that you agreed to post a link when you cross post a question.

    Why cross posting is an issue and how to do it is explained here. LINK

    cross posted at:
    http://www.ozgrid.com/forum/showthread.php?t=161141

  10. #10
    VBAX Newbie
    Joined
    Jun 2012
    Location
    Madurai
    Posts
    3
    Location
    hi,

    how to create a menu in user-form ?

  11. #11
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    For a menu, take a look Here

    For a context menu, Here

Posting Permissions

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