Thread: Create toolbar
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Fredrik E. Nilsen Fredrik E. Nilsen is offline
external usenet poster
 
Posts: 43
Default Create toolbar

Hi,

I use the following code to create a toolbar:

Sub CreateMenubar()

Dim iCtr As Long

Dim MacNames As Variant
Dim CapNamess As Variant
Dim TipText As Variant

Call RemoveMenubar

MacNames = Array("Line", _
"Column", _
"Pie", _
"LineColumn1", _
"LineColumn2", _
"Scatter", _
"StackedColumn")

CapNamess = Array("Line", _
"Column", _
"Pie", _
"LineColumn1", _
"LineColumn2", _
"Scatter", _
"StackedColumn")
TipText = Array("Line chart", _
"Column chart", _
"Pie chart", _
"Line/column 1 axis", _
"Line/column 2 axis", _
"Scatter chart", _
"Stacked column chart")
With Application.CommandBars.Add
.Name = ToolBarName
.Left = 200
.Top = 200
.Protection = msoBarNoProtection
.Visible = True
.Position = msoBarFloating

For iCtr = LBound(MacNames) To UBound(MacNames)
With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & MacNames(iCtr)
.Caption = CapNamess(iCtr)
.Style = msoButtonIconAndCaption
.FaceId = 71 + iCtr
.TooltipText = TipText(iCtr)
End With
Next iCtr
End With
End Sub


This code creates a toolbar with 7 buttons that control other macros.
I see now that I will need more buttons, up to 25 or 30 and I would
like to group them under menus on the toolbar, such as "Lines",
"Columns" etc. Is there an easy way to adjust the current code to
accomodate this?

--
Fredrik E. Nilsen