Create toolbar

F

Fredrik E. Nilsen

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top