情報関連 エクセルアプリケーションのコマンドバー(メニュー)を取得する
※より実装に近く表示させる為、コードの改行を避けています。スマホ等で閲覧される際は向きを変えてご覧ください。
※実装するバージョンによってはバージョンアップの仕様により動作しないコードもあります。実装には動作確認の上ご使用下さい。
Dim j As Long Dim sht As Worksheet Private Sub CommandBarGet() '************************************************* 'エクセルアプリケーションのコマンドバーを取得する '************************************************* 'メニューを取得する Dim i As Long, Bar As CommandBar For Each Bar In Application.CommandBars i = i + 1 Debug.Print i & " - " & Bar.Name Next End Sub Private Sub CommandBarControlGet() '************************************************* 'エクセルアプリケーションのコマンドバーを取得する '************************************************* 'メニューを取得する Dim i As Long, Bar As CommandBarControl Dim objCommandBar As CommandBar Set objCommandBar = Application.CommandBars("Worksheet Menu Bar") For Each Bar In objCommandBar.Controls i = i + 1 Debug.Print i & " - " & Bar.Caption Next End Sub Private Sub CommandBarControlMenuGet() '************************************************* 'エクセルアプリケーションのコマンドバーを取得する '************************************************* 'メニューを取得する Dim i As Long, Bar As CommandBarControl Dim objCommandBar As CommandBar Set objCommandBar = Application.CommandBars("Worksheet Menu Bar") Dim objCommandBarPopup As CommandBarPopup Set objCommandBarPopup = objCommandBar.Controls("ファイル(&F)") For Each Bar In objCommandBarPopup.Controls i = i + 1 Debug.Print i & " - " & Bar.Caption Next End Sub Private Sub CommandBarControlSubMenuGet() '************************************************* 'エクセルアプリケーションのコマンドバーを取得する '************************************************* 'メニューを取得する Dim i As Long, Bar As CommandBarControl Dim objCommandBar As CommandBar Set objCommandBar = Application.CommandBars("Worksheet Menu Bar") Dim objCommandBarPopup As CommandBarPopup Set objCommandBarPopup = objCommandBar.Controls("ファイル(&F)") Dim objCommandBarControl As CommandBarControl Set objCommandBarControl = objCommandBarPopup.Controls("送信(&D)") For Each Bar In objCommandBarControl.Controls i = i + 1 Debug.Print i & " - " & Bar.Caption Next End Sub '=========================================================================== Private Sub aCommandBarGet() '********************************************************* '全てのエクセルアプリケーションのコマンドバーを取得する '********************************************************* 'メニューを取得する j = 0 Set sht = ThisWorkbook.Worksheets.Add Dim i As Long, Bar As CommandBar For Each Bar In Application.CommandBars j = j + 1 i = i + 1 sht.Cells(j, 1).Value = Format(i, "0#") & "." & Bar.Name aCommandBarControlGet Bar.Name Next End Sub Private Sub aCommandBarControlGet(str1 As String) '************************************************* 'エクセルアプリケーションのコマンドバーを取得する '************************************************* 'メニューを取得する Dim i As Long, Bar As CommandBarControl Dim objCommandBar As CommandBar Set objCommandBar = Application.CommandBars(str1) For Each Bar In objCommandBar.Controls j = j + 1 i = i + 1 sht.Cells(j, 1).Value = " ├" & Format(i, "0#") & "." & Bar.Caption aCommandBarControlMenuGet str1, Bar.Caption Next End Sub Private Sub aCommandBarControlMenuGet(str1 As String, str2 As String) '************************************************* 'エクセルアプリケーションのコマンドバーを取得する '************************************************* 'メニューを取得する Dim i As Long, Bar As CommandBarControl Dim objCommandBar As CommandBar On Error GoTo TheEnd: Set objCommandBar = Application.CommandBars(str1) Dim objCommandBarPopup As CommandBarPopup Set objCommandBarPopup = objCommandBar.Controls(str2) For Each Bar In objCommandBarPopup.Controls j = j + 1 i = i + 1 sht.Cells(j, 1).Value = " ├" & Format(i, "0#") & "." & Bar.Caption aCommandBarControlSubMenuGet str1, str2, Bar.Caption Next TheEnd: End Sub Private Sub aCommandBarControlSubMenuGet(str1 As String, str2 As String, str3 As String) '************************************************* 'エクセルアプリケーションのコマンドバーを取得する '************************************************* 'メニューを取得する Dim i As Long, Bar As CommandBarControl Dim objCommandBar As CommandBar On Error GoTo TheEnd: Set objCommandBar = Application.CommandBars(str1) Dim objCommandBarPopup As CommandBarPopup Set objCommandBarPopup = objCommandBar.Controls(str2) Dim objCommandBarControl As CommandBarControl Set objCommandBarControl = objCommandBarPopup.Controls(str3) For Each Bar In objCommandBarControl.Controls j = j + 1 i = i + 1 sht.Cells(j, 1).Value = " ├" & Format(i, "0#") & "." & Bar.Caption Next TheEnd: End Sub |