Excel VBAをリボンに追加する |
最近のExcelはメニューがリボンになっていますよね。
自作のVBAプログラムをリボンに追加する方法を紹介します。
使用環境
・Excel(2007以上?)
・Custom UI Editor for Microsoft Office 2010
http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2009/08/06/7293.aspx
処理内容
1.おもむろにExcelのVBAを開く
※バージョンによっては「開発」タブが表示されていない場合がある
2.適当にメソッドを作る(引数に注意)
Sub Test(control As IRibbonControl)
Call MsgBox("test")
End Sub
3.Excelアドイン(xlam)で保存
4.Custom UI Editor for Microsoft Office 2010を開き、xlamを読み込む
5.「Office 2007 UI Part」を追加
6.メニューのInsert-SampleXML-Custom Tabをクリック
7.テンプレートが出力されるので、適宜直す
※customUIタグのxmlns属性を必ず直すこと
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon startFromScratch="false">
<tabs>
<tab id="ExcelTest" label="ExcelTest Tab">
<group id="ExcelTestGroup" label="ExcelTest Group">
<button id="ExcelTestButton" label="ExcelTestButton"
imageMso="HappyFace" size="large" onAction="Test" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
8.保存する
9.Excelからアドインを参照するとリボンに表示される
他の人に使ってもらう場合は8で保存したExcelアドイン(xlam)を配布します。
参考になれば幸いです。
よかったらクリックしてください。
にほんブログ村