Gruppe
Menue
Problem
Wie kann ich beim Öffnen der Arbeitsmappe eine neue Symbolleiste erstellen, die beim Schließen wieder gelöscht wird?
ClassModule: DieseArbeitsmappe
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call DeleteCmdBar
End Sub
Private Sub Workbook_Open()
Dim oBar As CommandBar
Dim oBtn As CommandBarButton
Dim iCounter As Integer
Call DeleteCmdBar
Set oBar = Application.CommandBars.Add( _
Name:="NewToolbar", _
temporary:=True, _
Position:=msoBarTop)
oBar.Visible = True
For iCounter = 1 To 5
Set oBtn = oBar.Controls.Add
With oBtn
.FaceId = 70 + iCounter
.Caption = "&" & iCounter & " Befehl"
.OnAction = "Befehl" & iCounter
End With
Next iCounter
End Sub
StandardModule: basMain
Sub Befehl1()
MsgBox "Ich bin Befehl 1"
End Sub
Sub Befehl2()
MsgBox "Ich bin Befehl 2"
End Sub
Sub Befehl3()
MsgBox "Ich bin Befehl 3"
End Sub
Sub Befehl4()
MsgBox "Ich bin Befehl 4"
End Sub
Sub Befehl5()
MsgBox "Ich bin Befehl 5"
End Sub
Sub DeleteCmdBar()
On Error Resume Next
Application.CommandBars("NewToolbar").Delete
On Error GoTo 0
End Sub