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