메뉴의 구조에 따라 약간의 조정이 필요할 수 있습니다. 그러나 일단 이것이 어떻게 작동하는지 이해한다면, 필요할 경우 변경을 할 수 있어야합니다.
먼저 사용자 지정 메뉴의 이름을 찾아야합니다. 이미 알고 있다면이 단계를 건너 뜁니다. 다른 사람이 반환 한 이름을 가져옵니다.
Dim x As Integer
For x = 1 To CommandBars.Count
If CommandBars(x).BuiltIn = False Then
Debug.Print x, CommandBars(x).Name, CommandBars(x).BuiltIn
End If
Next x
그런 다음 사용자 지정 메뉴의 이름을이 절차에 전달합니다. 내가 말했듯이 메뉴가 설정되는 방식에 따라 메뉴가 설정되어있을 수도 있고 그렇지 않을 수도 있습니다.
Private Sub ReadMenuControls(ByVal strCmdBar As String)
On Error GoTo errhandler
Dim x, y As Integer
Dim SubMenu As Object
With CommandBars(strCmdBar)
Debug.Print "Control Count Main: ", .Controls.Count
For x = 1 To .Controls.Count
With .Controls(x)
Debug.Print x & " <== " & .Caption & " ==>"
If .Type = 1 Then 'Command Button
Debug.Print "Button", x, .Caption, .Type, .ID, .FaceId, .Style, .onaction
Else 'If .Type = 10 Then 'Menu
Set SubMenu = CommandBars(strCmdBar).Controls(x)
For y = 1 To SubMenu.Controls.Count
With .Controls(y)
Debug.Print " * Button", y, .Caption, .Type, .ID, .FaceId, .Style, .onaction
End With
Next
End If
End With
Next
End With
Exit Sub
errhandler:
If Err.Number <> 438 Then
Debug.Print "ReadMenuControls", Err.Number, Err.description
End If
Resume Next
End Sub