Symbolleiste mit Textbutton erstellen

05.08.2001


Das folgende Beispiel erstellt eine neue Symbolleiste mit einem Textbutton,
dem ein Makro zugewiesen wird:

Const Symbolleistenname = "Eigene Symbolleiste"
Sub Symbolleiste_erstellen()
    On Error Resume Next
    Dim CB As CommandBar
    Dim CBC As CommandBarButton
    Set CB = Application.CommandBars(Symbolleistenname)
    Symbolleiste_löschen
    Set CB = Application.CommandBars.Add(Name:=Symbolleistenname, _
       temporary:=False, Position:=msoBarTop)
    Set CBC = CB.Controls.Add(Type:=msoControlButton)
    With CBC
        .Caption = "Meine Routine"
        .OnAction = "MachWas"
        .Style = msoButtonCaption
    End With
    CB.Visible = True
End Sub
Sub Symbolleiste_löschen()
    On Error Resume Next
    Application.CommandBars(Symbolleistenname).Delete
End Sub
Sub MachWas()
    MsgBox "Da bin ich", vbExclamation
End Sub