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

sounds like you don't have a toolbar called myToolbar

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Trefor" wrote in message
...
This code looks like what I am after, but when I ran it I get an Error 5
at:

Set CBar = .CommandBars("myToolbar")

Does anyone know why? Do I need something outside of the below to get this
to work?

--
Trefor


"Greg Wilson" wrote:

This was done very quickly and tested briefly. I'm short on time today.

It shows that you can use a standard commandbar button to display a popup
type toolbar (Position:=msoBarPopup) in the place of a standard menu type
control (msoControlPopup). I use a loop to populate the popup toolbar and
use
arrays to apply Caption, OnAction and FaceId properties. I also show that
this method has the advantage that you can change the status (e.g.
Enabled
property) of controls before displaying the popup.

I repeat, this was done quickly. My tests indicate that it's OK. Best of
luck !!!

Regards,
Greg


Sub XYZ()
Dim CBar As CommandBar, Popup As CommandBar
Dim ctrl As CommandBarControl
Dim CaptArr As Variant, MacroArr As Variant
Dim FaceIdArr As Variant
Dim i As Long

With Application
.ScreenUpdating = False
Set CBar = .CommandBars("myToolbar")
Set ctrl = CBar.Controls.Add(Temporary:=True)
With ctrl
.Caption = "Options"
.TooltipText = "Show Option list"
.OnAction = "ShowPopup"
.FaceId = 300
.Style = msoButtonIconAndCaption
End With
On Error Resume Next
.CommandBars("Options List").Delete
On Error GoTo 0
Set Popup = .CommandBars.Add(Position:=msoBarPopup, Temporary:=True)
Popup.Name = "Options List"
CaptArr = Array("Run Macro 1", "Run Macro 2", "Run Macro 3")
MacroArr = Array("Macro1", "Macro2", "Macro3")
FaceIdArr = Array(100, 101, 102)

For i = 0 To 2
Set ctrl = Popup.Controls.Add
With ctrl
.Caption = CaptArr(i)
.OnAction = MacroArr(i)
.FaceId = FaceIdArr(i)
End With
Next
CBar.Visible = True
.ScreenUpdating = True
End With
End Sub

Private Sub ShowPopup()
Dim i As Long
'This demo toggles the enabled status of the
'second button before showing the popup commandbar
With Application.CommandBars("Options List")
.Controls(2).Enabled = Not .Controls(2).Enabled
.ShowPopup
End With
End Sub

Sub Macro1()
MsgBox "You called Macro1"
End Sub

Sub Macro2()
MsgBox "You called Macro2"
End Sub

Sub Macro3()
MsgBox "You called Macro3"
End Sub



 
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 09:11 AM.

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

About Us

"It's about Microsoft Excel"