Gruppe
Menue
Problem
Die Daten eines jeden Menüpunktes eines vorgegebenen Menüs werden aufgelistet.
StandardModule: Modul1
Sub GetMenu()
Dim cmd As Object
Dim iCol As Integer
Dim sCntr As String
sCntr = "Excel-Hilfen"
On Error GoTo ERRORHANDLER
Set cmd = Application.CommandBars("Worksheet Menu Bar").Controls(sCntr)
iCol = 1
Range("A1").Value = "Übergeordnet"
Range("A2").Value = "Typ"
Range("A3").Value = "Aufschrift"
Range("A4").Value = "Makro"
Columns(1).Font.Bold = True
Call GetSubMenu(cmd, iCol)
Exit Sub
ERRORHANDLER:
MsgBox "Das Menü " & sCntr & " wurde nicht gefunden!"
End Sub
Private Sub GetSubMenu(cmd As Object, iCol As Integer)
Dim cnt As CommandBarControl
With cmd
For Each cnt In .Controls
iCol = iCol + 1
Cells(1, iCol).Value = cnt.Parent.Name
Cells(2, iCol).Value = TypeName(cnt)
Cells(3, iCol).Value = cnt.Caption
If TypeName(cnt) <> "CommandBarPopup" Then
Cells(4, iCol).Value = cnt.OnAction
Else
Call GetSubMenu(cnt, iCol)
End If
Next cnt
End With
End Sub