Okay,
Here is some code that will create a 5 button toolbar. You need to do the
following
- change the sToolBar value to something you want
- change the button captions, from Button 1, 2 etc to your button ids
- change the OnAction property values from macro1, etc. to your macros
- if you want button icons change the faceid property (John Walkenbach has a
utility to help you at
http://j-walk.com/ss/excel/tips/tip67.htm to help
find the values of
the FaceIds), and remove the .Style property, or add .style property to al
buttons and the caption is shown on the button
- add this code toe the ThisWorkbook code module of the spreadsheet before
you save it as an addin
Option Explicit
Const sToolbar As String = "PCOR's Toolbar"
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.CommandBars(sToolbar).Delete
On Error GoTo 0
End Sub
Private Sub Workbook_Open()
Dim cMenu1 As CommandBarControl
Dim cbToolbar As CommandBar
On Error Resume Next
Application.CommandBars(sToolbar).Delete
On Error GoTo 0
Set cbToolbar = Application.CommandBars.Add(sToolbar, , False, True)
With cbToolbar
With .Controls.Add(Type:=msoControlButton)
.BeginGroup = True
.Caption = "Button 1"
.FaceId = 1
.OnAction = "macro1"
End With
With .Controls.Add(Type:=msoControlButton)
.BeginGroup = True
.Caption = "Button 2"
.FaceId = 2
.OnAction = "macro2"
End With
With .Controls.Add(Type:=msoControlButton)
.BeginGroup = True
.Caption = "Button 2"
.FaceId = 3
.OnAction = "macro3"
End With
With .Controls.Add(Type:=msoControlButton)
.BeginGroup = True
.Caption = "Button 4"
.FaceId = 4
.OnAction = "macro4"
End With
With .Controls.Add(Type:=msoControlButton)
.BeginGroup = True
.Caption = "Button 5"
.FaceId = 5
.OnAction = "macro5"
End With
.Visible = True
.Position = msoBarTop
End With
End Sub
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)