Visual Basic Editor コマンドバー機能一覧
サンプルではVisual Basic Editorのコマンドバーと、各コマンドバーの
機能一覧及びFaceを取得し、ActiveSheetに書き出します。


Sub GetVBECommandBarControls()

    Dim i As Long, j As Long
    Dim MyCtrl As CommandBarButton

    '画面描画停止
    Application.ScreenUpdating = False

    On Error Resume Next

    For i = 1 To Application.VBE.CommandBars.Count
        'コマンドバーの主要なプロパティーの値書き出し
        With Application.VBE.CommandBars(i)
            Cells(1, i).Value = .Name
            Cells(2, i).Value = .NameLocal
            Cells(3, i).Value = "BuiltIn: " & .BuiltIn
            Cells(4, i).Value = "Context: " & .Context
            Cells(5, i).Value = "Index: " & .Index
            Cells(6, i).Value = "Position: " & .Position
            Cells(7, i).Value = "Protection: " & .Protection
            Cells(8, i).Value = "RowIndex: " & .RowIndex
            Cells(9, i).Value = "Type: " & .Type
            Cells(10, i).Value = "Top: " & .Top
            
            For j = 1 To .Controls.Count
                'コントロールの主要プロパティーの値書き出し
                With .Controls(j)
                Cells((j - 1) * 4 + 11 + 1, i).Value = "Caption:" & .Caption
                Cells((j - 1) * 4 + 11 + 2, i).Value = "ID: " & .ID
                Cells((j - 1) * 4 + 11 + 3, i).Value = "Index: " & .Index
                'Face取得
                If .Type = msoControlButton Then
                    Set MyCtrl = Application.VBE.CommandBars(i).Controls(j)
                    MyCtrl.CopyFace
                    Cells((j - 1) * 4 + 11 + 4, i).Select
                    ActiveSheet.Paste
                    Set MyCtrl = Nothing
                End If
                End With
            Next j

        End With
    Next i

    ActiveSheet.UsedRange.EntireColumn.AutoFit
    ActiveWindow.ScrollColumn = 1
    ActiveWindow.ScrollRow = 1
    ActiveWindow.Zoom = 75
    Application.ScreenUpdating = True

End Sub


※個別にボタンの機能を実行するには・・・

    Application.VBE.CommandBars("Project Window Insert") _
	             .Controls("ユーザー フォーム(&U)").Execute
	             
などのようにExecuteメソッドを用います。

※97と2000ではIndexが異なったり、NameやCaptionのカタカナが97では半角であったり
など、若干扱いが異なる場合があります。Application.Versionで処理分岐を行ったり、
IDが同じであることが確認できればFindControlメソッドを使う、などの注意が必要です。

Excel97,2000



戻る


Excel Word Access VBA! モーグ