Originally Posted by
xld
This one means that you don't take the time to add a toolbar manually but
use this code to create and when finished, delete the toolbar for the current workbook.
Create the toolbar dynamically
[vba]
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Delete toolbar that you have created
Application.CommandBars("myToolbar").Delete
On Error GoTo 0
End Sub
Private Sub Workbook_Open()
When workbook opens, create toolbar
Dim oCB As CommandBar
Dim oCtl As CommandBarControl
On Error Resume Next
If for some reason the toolbar is still present, delete it, or you will get an error
Application.CommandBars("myToolbar").Delete
On Error GoTo 0
Set oCB = Application.CommandBars.Add(Name:="myToolbar", temporary:=True)
With oCB
Set oCtl = .Controls.Add(Type:=msoControlButton)
With oCtl
.BeginGroup = True
.Caption = "savenv"
The line beneath this sentence means when pushed on button with
caption savenv execute macro savenv
.OnAction = "savenv"
.FaceId = 27
End With
Set oCtl = .Controls.Add(Type:=msoControlButton)
With oCtl
.Caption = "savemyprog"
.OnAction = "savemyprog"
.FaceId = 28
End With
Set oCtl = .Controls.Add(Type:=msoControlButton)
With oCtl
.Caption = "macro4"
.OnAction = "macro4"
.FaceId = 29
End With
Set oCtl = .Controls.Add(Type:=msoControlButton)
With oCtl
.Caption = "dater"
.OnAction = "dater"
.FaceId = 30
End With
.Visible = True
Position of the toolbar
.Position = msoBarTop
End With
End Sub
[/vba]