Neue Menüleiste erstellen

30.05.2002

 

Dieses Beispiel erstellt eine neue Menüleiste.
Die bereits vorhandene Menüleiste wird dabei entfernt.

Const MenüName = "Mein_Menü"
Sub Neues_Menü()
    Call Menü_zurücksetzen
    Application.CommandBars("Worksheet Menu Bar").Enabled = False
    Set MB = CommandBars.Add(Name:=MenüName, MenuBar:=True)
    Set M1 = MB.Controls.Add(Type:=msoControlPopup)
    Set M2 = MB.Controls.Add(Type:=msoControlPopup)
    Set M3 = MB.Controls.Add(Type:=msoControlPopup)
    Set M4 = MB.Controls.Add(Type:=msoControlPopup)
    M1.Caption = "Menü 1"
    M2.Caption = "Menü 2"
    M3.Caption = "Menü 3"
    M4.Caption = "Menü 4"
    Set cmdButton = M1.Controls.Add
    With cmdButton
      .Caption = "Eintrag 1"
      .OnAction = "machwas1"
      .Style = msoButtonCaption
    End With
    Set cmdButton = M2.Controls.Add
    With cmdButton
      .Caption = "Eintrag 2"
      .OnAction = "machwas2"
      .Style = msoButtonCaption
    End With
    Set cmdButton = M3.Controls.Add
    With cmdButton
      .Caption = "Eintrag 3"
      .OnAction = "machwas3"
      .Style = msoButtonCaption
    End With
    Set cmdButton = M4.Controls.Add
    With cmdButton
      .Caption = "Eintrag 4"
      .OnAction = "machwas4"
      .Style = msoButtonCaption
    End With
    CommandBars(MenüName).Visible = True
End Sub
Sub Menü_zurücksetzen()
    On Error Resume Next
    Application.CommandBars(MenüName).Delete
    Application.CommandBars("Worksheet Menu Bar").Enabled = True
End Sub
Sub MachWas1()
    MsgBox "Hallo 1"
End Sub
Sub MachWas2()
    MsgBox "Hallo 2"
End Sub
Sub MachWas3()
    MsgBox "Hallo 3"
End Sub
Sub MachWas4()
    MsgBox "Hallo 4"
End Sub
 

Beispieldatei - 9 KB