Option Explicit Sub auto_open() 'ここで起動時に(念のためいったん削除してから)メニューを追加(作成)します '既にauto_open() を記述している場合は、以下の2行を追加します。 Menu削除 1 Menu追加 1 ' End Sub Sub auto_close() 'エクセル終了時にメニューを削除します ' Menu削除 1 ' End Sub Sub Menu追加(num%) 'ダミーの引数(num%)を付けているのは、「ツール」「マクロ」から指定できないようにするため Dim myBar As CommandBar Dim myCtrl As CommandBarControl ' Application.CommandBars("Worksheet Menu Bar").Reset 20021020変更 Menu削除 1 '20021020変更 Set myBar = CommandBars("Worksheet Menu Bar") Set myCtrl = myBar.Controls.Add(Type:=msoControlPopup, Temporary:=True) With myCtrl '最初にココで、メニューバーに追加するメニュー名を指定する。 .Caption = "MyTools(&X)" '(&英数字)はショートカットの指定(なくてもOK) .Visible = True .Controls.Add Type:=msoControlButton .Controls(1).Caption = "電卓の起動(&0)" '表示されるメニューの名前を指定 .Controls(1).OnAction = "Dentaku" '起動するマクロを指定 .Controls(1).FaceId = 283 'メニューの左に表示されるアイコンを指定(指定しなくてもOK) .Controls.Add Type:=msoControlButton .Controls(2).Caption = "ウィンドウの上下整列(&1)" 'メニュー名の後ろに(&英数字)と記述すると、ショートカットの指定になる(なくてもOK) .Controls(2).OnAction = "ウィンドウの上下整列" .Controls(2).FaceId = 298 .Controls(2).BeginGroup = True 'これを指定すると、メニューをセパレートする横棒が入る .Controls.Add Type:=msoControlButton .Controls(3).Caption = "アクティブシートの複数画面表示(&2)" .Controls(3).OnAction = "同一Sheetの複数画面表示" .Controls(3).FaceId = 585 .Controls.Add Type:=msoControlButton .Controls(4).Caption = "セル縦位置中央揃え(&3)" .Controls(4).OnAction = "セル縦位置中央揃え" .Controls(4).FaceId = 2062 .Controls(4).BeginGroup = True .Controls.Add Type:=msoControlButton .Controls(5).Caption = "セル縦位置上詰め(&4)" .Controls(5).OnAction = "セル縦位置上詰め" .Controls(5).FaceId = 2061 .Controls.Add Type:=msoControlButton .Controls(6).Caption = "列幅で折り返し(&5)" .Controls(6).OnAction = "列幅折り返し表示" .Controls(6).FaceId = 119 .Controls.Add Type:=msoControlButton .Controls(7).Caption = "全シートをHOMEポジションに(&6)" .Controls(7).OnAction = "To_Home" .Controls(7).FaceId = 1826 .Controls(7).BeginGroup = True .Controls.Add Type:=msoControlButton .Controls(8).Caption = "入力後のセル移動方向の変更(&7)" .Controls(8).OnAction = "セル移動方向切替" .Controls(8).FaceId = 133 .Controls.Add Type:=msoControlButton .Controls(9).Caption = "枠線の表示切替(&W)" .Controls(9).OnAction = "枠線表示切替え" .Controls(9).FaceId = 217 .Controls.Add Type:=msoControlButton .Controls(10).Caption = "行列番号の表示切替(&G)" .Controls(10).OnAction = "行列番号表示切替" .Controls(10).FaceId = 800 .Controls.Add Type:=msoControlButton .Controls(11).Caption = "A1形式R1C1形式の切替(&A)" .Controls(11).OnAction = "A1_R1C1" .Controls(11).FaceId = 503 .Controls.Add Type:=msoControlButton .Controls(12).Caption = "最近使用したファイルの一覧に追加(&S)" .Controls(12).OnAction = "Add_RecentFiles" .Controls(12).FaceId = 462 .Controls.Add Type:=msoControlButton .Controls(13).Caption = "フォント設定の一覧を表示する(&V)" .Controls(13).OnAction = "font_check" .Controls(13).FaceId = 291 .Controls(13).BeginGroup = True .Controls.Add Type:=msoControlButton .Controls(14).Caption = "全ての隠しシートを表示する(&F)" .Controls(14).OnAction = "全シート表示" .Controls(14).FaceId = 2587 .Controls.Add Type:=msoControlButton .Controls(15).Caption = "シートを確認しながら非表示にする(&H)" .Controls(15).OnAction = "シート隠蔽" .Controls(15).FaceId = 1641 End With End Sub Sub Menu削除(num%) Dim myBar As CommandBar Set myBar = CommandBars("Worksheet Menu Bar") On Error Resume Next myBar.Controls("MyTools(&X)").DELETE On Error GoTo 0 End Sub