Excel2007のリボンメニューカスタマイズ
ちょっと知り合いからの依頼でエクセルのメニューを作らなくてはいけなくなったので、その記録を。
ちなみにExcelだけではなくWord、PowerPointでも同じ方法で出来るみたいです。(AccessやOutlookは別の方法です。)
まずは適当なモジュールをブックに追加して保存します。
Sub test(control As IRibbonControl) MsgBox "Ribon Menu Test!" End Sub
このとき「マクロ有効ブック(xlsm)」形式で保存しましょう。
※今回は「ribontest.xlsm」で保存しています。
次に、「customUI」フォルダを作成し、その中に「custumUI.xml」というxmlファイルを以下の内容で保存します。
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="customTab" label="Custom Tab">
<group id="customGroup" label="Custom Group">
<button id="customButton" label="Custom Button" imageMso="HappyFace"
size="large" onAction="ThisWorkbook.test" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
先ほど保存した「ribontest.xlsm」のファイル名の後ろに「.zip」を付け足し「ribontest.xlsm.zip」にします。
このとき以下のメッセージが出た場合は「はい」を選択します。

「ribontest.xlsm.zip」に先ほど作成した「customUI.xml」を「customUI」フォルダごとドロップします。
「ribontest.xlsm.zip」フォルダを開き「_rels」フォルダを適当な場所にドロップします。
「_rels」フォルダを開くと「.rels」ファイルがあるので、メモ帳など適当なエディタで開きます。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/ 2006/relationships/extended-properties" Target="docProps/app.xml"/> <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/ 2006/relationships/metadata/core-properties" Target="docProps/core.xml"/> <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/ 2006/relationships/officeDocument" Target="xl/workbook.xml"/> </Relationships>
このように記述してあるので、以下のコードを<Relationships></Relationships>の間の最後に追加します。
<Relationship Type="http://schemas.microsoft.com/office/2006/relationships/ui/ extensibility" Target="/customUI/customUI.xml" Id="customUIRelID" />
以下のようなコードが出来上がります。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/ 2006/relationships/extended-properties" Target="docProps/app.xml"/> <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/ 2006/relationships/metadata/core-properties" Target="docProps/core.xml"/> <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/ 2006/relationships/officeDocument" Target="xl/workbook.xml"/> <Relationship Type="http://schemas.microsoft.com/office/2006/relationships/ui/ extensibility"Target="/customUI/customUI.xml" Id="customUIRelID" /> </Relationships>
「.rels」ファイルを保存して、「_rels」フォルダごと「ribontest.xlsm.zip」圧縮フォルダにドロップします。
「ribontest.xlsm.zip」のファイル名を「ribontest.xlsm」に戻します。
「ribontest.xlsm」ファイルを開き、リボンメニューに「Custom Tab」というタブが出来ているので、それをクリックし、「Custom Group」の「Custom Button」をクリックします。
以下のメッセージが出てきたら成功です。

【参考にしたホームページ】
●2007 Office Fluent リボンをカスタマイズする (開発者向け) (パート 1/3)
http://msdn.microsoft.com/ja-jp/library/aa338202(office.12).aspx
●あるSEのつぶやき>Excel 2007 アドインでリボンメニューを作成する方法
http://fnya.cocolog-nifty.com/blog/2009/03/excel-2007-e739.html
リボンに表示させるアイコンを選びたい場合は、「customUI.xml」内の
<button id="customButton" label="Custom Button" imageMso="HappyFace" size="large" onAction="ThisWorkbook.test" />
「imageMso=”HappyFace”」の部分を変更することで好きなアイコンに変更できます。
アイコンの名前を知りたい場合は、以下のツールを利用すると便利です。
Download details: 2007 Office System Add-In: Icons Gallery
お疲れです。
早速見てますよ!
2007でそんな需要があることにびっくり。
いまだに慣れないけど、リボンのほうが使いやすい人もいるんだね。
面白いアプローチだよね。
正直考えたこともなかった。
ためになるので、またいろいろ更新してってね。
@10keyさん
お疲れ様です。早速コメントどうもです。
まぁ、マクロボタンを普通にシートに貼っても良いんですけど、よりスマートに出来ないかと思ってですね(^^ゞ
頑張って作れば、上記の方法でOffice2003と同じメニューを作ることも可能ですよ。かなりめんどくさいけど。
また、更新頑張ります。