即効テクニック |
サンプルではワークシートメニューバー(CommandBars("Worksheet Menu Bar"))のコントロール(ControlPopup)と一階層下のコントロール(ControllPopup、及びControlButton)を書き出します。
Sub GetWorksheetMenuCtrl() Dim i As Integer, j As Integer Dim CBar As CommandBar Set CBar = Application.CommandBars(1) Cells.Clear With CBar.Controls For i = 1 To .Count Cells(1, i).Value = "Caption: " & .Item(i).Caption Cells(2, i).Value = "Index: " & .Item(i).Index Cells(3, i).Value = "ID: " & .Item(i).ID With .Item(i).Controls For j = 1 To .Count Cells(4 * j + 2, i).Value = "Caption: " & .Item(j).Caption Cells(4 * j + 3, i).Value = "Index: " & .Item(j).Index Cells(4 * j + 4, i).Value = "ID: " & .Item(j).ID Next j End With Next i End With ActiveSheet.UsedRange.EntireColumn.AutoFit ActiveSheet.UsedRange.Resize(3).Font.Bold = True End Sub
※Set CBar = Application.CommandBars(1)の部分をSet CBar = Application.VBE.CommandBars(1)とするとVisual Basic Editorのメニューバー機能一覧を作成することが出来ます。 上記サンプルで作成される機能一覧からIDを指定してコントロールを実行するにはFindControlメソッドを使用します。