Tuesday, October 06, 2009

Excel Toolbars

Note: Make the toolbar more robust:

Call your proc but add the full path as per the workbook with the code

.OnAction = "'" & ThisWorkbook.Path & "\" & ThisWorkbook.Name & "'!SystemInfo"

eg
Public Sub Auto_Open()
Dim cBar As commandbar
Dim cbarReports As commandbar
Dim myControl As CommandBarButton

For Each cBar In Application.CommandBars
If cBar.Name = "Toolbar_Name" Then
cBar.Delete
End If
Next cBar

Set cbarReports = CommandBars.Add("Toolbar_Name")
'Add System button
Set myControl = cbarReports.Controls.Add(Type:=msoControlButton)

With myControl
.Style = msoButtonCaption
.BeginGroup = True
.Caption = "About"
.OnAction = "'" & ThisWorkbook.Path & "\" & ThisWorkbook.Name & "'!SystemInfo"
End With

End Sub

No comments: