Gruppe
Menue
Bereich
Control
Thema
Prüfen, ob ein Menü vorhanden ist
Problem
Wie kann ich überprüfen, ob in der Arbeitsblattmenüleiste ein bestimmtes Menü enthalten ist und wo es sich, wenn ja, befindet?
Lösung
Geben Sie den nachfolgenden Code in ein Standardmodul ein und weisen Sie ihn einer Schaltfläche zu.
StandardModule: basMain
Sub MenuTest()
Dim oCntr As CommandBarControl
Dim bln As Boolean
With Application.CommandBars("Worksheet Menu Bar")
For Each oCntr In .Controls
If oCntr.Type = msoControlButtonPopup And _
oCntr.Caption = "MeinMenue" Then
bln = True
Exit For
End If
Next oCntr
End With
If bln = True Then
MsgBox "Das Menü ""MeinMenue"" existiert!"
Else
MsgBox "Das Menü ""MeinMenue"" existiert nicht!"
End If
End Sub