Hinzufügen von Popup-Kontrollen zu Befehlsleisten
Popup-Kontrollen
ich möchte einer Befehlsleiste ein Popup (oder Dropdown) - Steuerelement hinzufügen. Leider funktioniert bei mir nur "msoControlPopup", damit bekomme ich eine Schaltfläche nur für Text. Ich möchte vorzugsweise eine Schaltfläche mit Symbol, aber beim Einfügen bekomme ich immer einen Laufzeitfehler (Nr. 5, Ungültiger Prozeduraufruf oder ungültiges Argument).
Ich habe verschiedene Steuerelemente ausprobiert, die mso-Konstanten sind im Objektkatalog vorhanden und ich sehe beim debuggen auch ihren Wert, außerdem habe ich auch mit den Variablendeklarationen herumgespielt, alles erfolglos.
Wäre toll, wenn jemand eine Idee hätte.
Sub BefehlsLeisteTest()
Dim LeistenName As String
Dim IniBlatt As Variant, KnopfElement As Variant, PopupElement As Variant, UnterElement As Variant
Set IniSheet = Workbooks("DateiMitCode.xls").Worksheets("BlattMitBild")
LeistenName = "TestLeiste"
' Löschen der Befehlsleiste, falls bereits vorhanden
On Error Resume Next
CommandBars(LeistenName).Delete
On Error GoTo 0
' Hinzufügen einer neuen Befehlsleiste
Application.CommandBars.Add (LeistenName)
' Hinzufügen eines Knopfs zur neuen Befehlsleiste
IniBlatt.Shapes("Bild 1").CopyPicture
With Application.CommandBars(LeistenName)
Set KnopfElement = .Controls.Add
End With
With KnopfElement
.Style = msoButtonAutomatic
.PasteFace
.OnAction = "MakroStart"
.Caption = "Knopf 1"
End With
' Hinzufügen eines Popup - Steuerelementes zur neuen Befehlsleiste
IniBlatt.Shapes("Bild 1").CopyPicture
With Application.CommandBars(LeistenName)
Set PopupElement = .Controls.Add(Type:=msoControlPopup)
' Set PopupElement = .Controls.Add(Type:=msoControlSplitButtonPopup)
' Set PopupElement = .Controls.Add(Type:=msoControlSplitButtonMRUPopup)
' Set PopupElement = .Controls.Add(Type:=msoControlButtonDropdown)
End With
With PopupElement
.Caption = "Popup-Element"
' .Style = msoButtonAutomatic
' .PasteFace
End With
' Hinzufügen eines Knopfs zum Popup - Steuerelement
IniBlatt.Shapes("Bild 1").CopyPicture
Set UnterElement = PopupElement.Controls.Add
With UnterElement
.Style = msoButtonAutomatic
.PasteFace
.OnAction = "MakroStart"
.Caption = "SubKnopf 1"
End With
' Anzeigen der Befehlsleiste
Application.CommandBars(LeistenName).Visible = True
End Sub