Wednesday, July 16, 2008

Code to create a toolbar Icon on excel

Private Sub Workbook_Open()
Dim cmd As CommandBarButton

Dim bar As CommandBar

On Error Resume Next

Application.CommandBars("New").Delete

Set bar = Application.CommandBars.Add("New")

bar.Visible = True

bar.Position = msoBarTop

bar.Protection = msoBarNoMove

Set cmd = bar.Controls.Add(Type:=msoControlButton)

cmd.FaceId = 351

cmd.OnAction = "GetReport"

cmd.Caption = " Report"

End Sub