View Full Version : Create custom submenu using commandbar
j312ry
01-03-2012, 07:48 PM
Hi All Gurus,
I want to know on how to add submenu into custom menu we already have.
My code is just like this :
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
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
mohanvijay
01-03-2012, 08:20 PM
Little example
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"
j312ry
01-03-2012, 08:56 PM
Great It works !!
Thank you so much :beerchug:
j312ry
01-03-2012, 09:33 PM
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
j312ry
01-03-2012, 09:38 PM
Sorry, i mean : Su_Po.faceid = xxx
This code return an error.
Thanks before..
Little example
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"
mohanvijay
01-03-2012, 10:21 PM
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
mikerickson
01-04-2012, 12:55 AM
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 (http://www.excelguru.ca/content.php?184)
cross posted at:
http://www.ozgrid.com/forum/showthread.php?t=161141
j312ry
01-04-2012, 01:19 AM
Hi mohanvijay many thanks for your quick reply..:beerchug:
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
j312ry
01-04-2012, 01:26 AM
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..:friends:
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 (http://www.excelguru.ca/content.php?184)
cross posted at:
http://www.ozgrid.com/forum/showthread.php?t=161141
olcsaravanan
06-23-2012, 08:05 AM
hi,
how to create a menu in user-form ?
For a menu, take a look Here (http://www.xcelfiles.com/API_Userform_MenuMaker.html)
For a context menu, Here (http://word.mvps.org/FAQs/Userforms/AddRightClickMenu.htm)
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.