LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Creating sub menu in Command bar

Hi All,

it is possible to add an image (icon) to the msoControlPopup, like it is the
case for the msoControlButton ?For answers thanks in advance.

Cheers,

Florian

"Greg Wilson" wrote:

For the sake of brevity, I only show how to:
1) Create a new toolbar
2) Add a popup type control (that supports menu items) to the toolbar
2) Add menu items to the popup control (menu control)
3) Add a popup control (that supports submenu items) to the first popup
control
4) Add submenu items to the second popup control
5) Use arrays and loops to drastically cut down on the code requirement.

You can continue the same branching process indefinately to my knowledge.

Regards,
Greg

Sub MakeNewMenu()
Dim CB As CommandBar
Dim NewMenu As CommandBarControl
Dim MenuItm As CommandBarControl
Dim SubMenuItm As CommandBarControl
Dim Arr1 As Variant, Arr2 As Variant
Dim Arr3 As Variant
Dim i As Integer

With Application
.ScreenUpdating = False
'Menu item caption list
Arr1 = Array("Caption 1", "Caption 2", _
"Caption 3", "Caption 4", "Caption 5")
'Menu item macro list
Arr2 = Array("Menu macro 1", "Menu macro 2", _
"Menu macro 3", "Menu macro 4", "Menu macro 5")
'Menu item FaceId list
Arr3 = Array(100, 101, 102, 103, 104)
Set CB = .CommandBars.Add("Data Analysis", Temporary:=True)
Set NewMenu = CB.Controls.Add(msoControlPopup)
NewMenu.Caption = "Menu items"
'ToolTipText supported on this level only
NewMenu.TooltipText = "Select from my macros"

'When referencing elements in an array, the first
'element has an index value of zero (hence 0 to 4)
For i = 0 To 4
Set MenuItm = NewMenu.Controls.Add
With MenuItm
.Caption = Arr1(i)
.Style = msoButtonIconAndCaption
.OnAction = Arr2(i)
.FaceId = Arr3(i)
End With
Next
'Submenu item caption list
Arr1 = Array("Caption 6", "Caption 7", "Caption 8", _
"Caption 9", "Caption 10")
'Submenu item macro list
Arr2 = Array("Submenu macro 1", "Submenu macro 2", _
"Submenu macro 3", "Submenu macro 4", "Submenu macro 5")
'Submenu item FaceId list
Arr3 = Array(200, 201, 202, 203, 204)
'Now add popup type control to support the submenus
Set MenuItm = NewMenu.Controls.Add(msoControlPopup)
MenuItm.Caption = "Sub menu items"
For i = 0 To 4
Set SubMenuItm = MenuItm.Controls.Add
With SubMenuItm
.Caption = Arr1(i)
.Style = msoButtonIconAndCaption
.OnAction = Arr2(i)
.FaceId = Arr3(i)
End With
Next
CB.Visible = True
DoEvents
.ScreenUpdating = True
End With
End Sub

"Anders" wrote:

Hi all,

I would like to create a command bar that contains a menu with sub menues.
Do anyone know how to do this?

Menu
-------
Menu Item1
Menu Item2 - Sub menu item - Sub sub menu item

Regards
Anders

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Command to RightClick Menu Ronbo Excel Programming 3 January 14th 05 02:05 AM
Add Command to Right-Click Menu Andy Excel Programming 3 January 11th 05 02:00 PM
there is no XML command on my data menu Mattie Excel Worksheet Functions 1 November 27th 04 09:00 AM
Command Bar Menu - Management kraljb[_2_] Excel Programming 2 October 26th 04 04:57 PM
Execute a menu command with VBA? Susan[_3_] Excel Programming 2 May 1st 04 07:45 AM


All times are GMT +1. The time now is 12:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"