「Excel VBA Tips」ではExcel VBAを使用していて気付いたことを取り上げて行きます。
初回から3回に渡り、XML形式のファイル”customUI14.xml”を使用したFulentリボンの機能についてご紹介いたしてきましたが、今回が最後になります。
最後はXML形式でのFulentリボンのコールバック関数について具体的にXMLファイルとVBAに設定して行きます。
※動作は32bit版Excel 2016と64bit版Excel 2021の バージョン2404(ビルド 17531.20152)を使用して検証しています。
コールバック関数を扱うにはマクロ有効ブック等が必要
コールバック関数を使用するためには、マクロ有効ブック”.xlsm”やExcelアドイン”.xlam”どちらかのファイル形式にしなければなりません。
ただそうなるとそのような悪意のあるプログラムが含まれている可能性があるファイルをネット上からダウンロードする事はマルウェア対策として許されていない認識です。
端的にマクロ有効ブック”.xlsm”のままでサンプルファイルを作る事は出来ないので、マクロ有効ブックを展開してできる個々のフォルダー・ファイルのなかで必要になる右図赤枠で囲んだフォルダー・ファイルをZIP圧縮してダウンロードできる形にいたします。
そのためお手数ではありますが、ダウンロードしたフォルダー・ファイルを使ってつぎの1から4の加工をしていただく必要がありますのでお含み置きください。
- 赤枠を付けていない2つのフォルダー”docProps”と”xl”については、お手元でマクロ有効ブック”.xlsm”新規に作成・保存していただき、拡張子を”.zip”に変更してマクロ有効ブック”.xlsm”の中身を展開し、それをコピー & 貼り付けしたものをご使用ください。
- フォルダー・ファイルがすべてそろったら、すべてを選択してZIP圧縮しファイル名の拡張子を”.xlsm”に変更してください。


- 作成したマクロ有効ブック”.xlsm”を起動するのですが、起動する際に下記の注意点がありますので必ずご一読ください。
- その後で、VBEを開き標準モジュールを追加していただき、後段でご紹介するコーディング事例をコピーして標準モジュールの先頭に貼り付け・保存していただければ幸いです。



※画面キャプチャーでイミディエイトウィンドウを開いているのは”debug.print”を確認するために使用します。
すべてのコールバック関数を確認できている分けではない
大変恐縮ですが、確認できていないコールバック関数がいくつかあり、それは次のよう理由からになります。
- 使い方がよくわからないもの
- 設定してもパラメータが反映されないなどの理由によるもの
- 設定するとエラーになるもの

※個々のコントロール(タグ)のコールバック関数を押しなべてすべて確認しているわけではありませんのあらかじめお含み置きください。
実際に確認したタブとコールバック関数の組み合わせで該当したものはつぎのようになります。
| タブ | CallBack | 理由 | 説明 |
|---|---|---|---|
| box | getVisible | 1 | isibleパラメータにFalseをセットしても表示される |
| button | getShowImage | 1 | showImageパラメータにFalseをセットしても表示される |
| getShowLabel | 1 | showLabelパラメータにFalseをセットしても表示される | |
| checkBox | getShowLabel | 2 | |
| control | onAction | 2 | |
| gallery | getItemScreenTip | 2 | |
| getItemSuperTip | 2 | ||
| menu | onAction | 2 |
属性とコールバック関数はどちらか一方しか設定できないものがある
個々のコントロール(タグ)に設定している属性と、その属性を動的に設定するためのコールバック関数は、両方XML形式のファイル”customUI14.xml”に設定して起動するとエラーメッセージが表示されるものがあります。
※一部に、属性にセットする値によってエラーになる/ならないが変化するものもあります。
また少し組み合わせの内容が異なりますが、comboBoxコントロール(タグ)やgallryコントロール(タグ)では、一連のgetItemCountコールバック関数を指定した時に、itemコントロール(タグ)は使わなくなるのですが(残した場合でも実際に使用されるのはコールバック関数)、ただしそのまま残っていてもエラーにはなりません。
※本来は削除すべきですが、コーディング事例では注釈にして残してあります。

前回ご紹介した❝cutomUI14.xml❞ファイルのコーディング事例は、この理由からかなり変更が加わっていますのであらかじめお含み置きください。
確認した属性とコールバック関数のどちらか一方を選択する組み合わせ
| 属性 | CallBack |
|---|---|
| enabled | getEnabled |
| image | getImage |
| itemHeight | getItemHeight |
| itemWidth | getItemWidth |
| label | getLabel |
| 属性 | CallBack |
|---|---|
| screentip | getScreentip |
| showLabel | getShowLabel |
| size | getSize |
| supertip | getSupertip |
| title | getTitle |
| visible | getVisible |
| 属性 | 値 | CallBack | 備考 |
|---|---|---|---|
| showImage | True | getShowImage | FalseはOK. でもイメージ は表示 |
checkboxのgetPressedコールバック関数には問題がある
checkboxコントロール(タグ)のgetPressedコールバック関数は「癖が強い」と言いますか、チェックボックスがチェックされているかどうかを取得するためのパラメータが存在しません。

getPressedコールバック関数が設定されているtoggleButtonの場合は、パラメータで状態が押されているかどうかを示す値を取得する事ができますが…
※なおcheckboxコントロール(タグ)の中でgetPressedとonActionコールバック関数を両方設定すると起動時にエラーが返るのでどちらかを設定します。
onActionコールバック関数にしても、getPressedコールバック関数にしても、コールされた時に事前に定義したBoolean型グローバル変数のTrue/Falseでチェックボックスがチェックしているか?/いないか?の状態を独自に保持することが必要になります。
ただしgetPressedコールバック関数ではcheckboxコントロール(タグ)を連続して変更した場合に、二度目の操作ではgetPressedコールバック関数が呼ばれないのです…
※再現性があるのでこれはバグかもしくはそのような仕様になっていると言えます。
そのためわざわざBoolean型グローバル変数に値を保存しコール時に反転するコーディングをしたとしても、変数の値を正しくキープする事ができません。
従って、checkboxコントロール(タグ)ではonActionコールバック関数を使用するのが正解です。
※getPressedコールバック関数は使えないのですが、確認の履歴としてコーディングを注釈で残していますのであらかじめお含み置きください。
- カスタムタブが有効化された時点で1度getPressedコールバック関数はシステムからコールされます。
- なおcustomUIコントロール(タグ)のonLoadコールバック関数でBoolean型グローバル変数にTrueをセットすると、チェックボックスにチェックが入らずに起動され、Falseの場合はチェックが入った状態で起動されます。
- カスタムタブが有効化された時にonLoadコールバック関数が一番最初にシステムからコールされて、その後にgetPressedコールバック関数がシステムからコールされるので、初期設定したBoolean型グローバル変数は一度反転される事になり、チェックボックスのチェック状態とBoolean型グローバル変数の真偽は一致します。
コーディング事例
今回使用するするコーディング事例ですが、まずは前回で使用した❝cutomUI14.xml❞ファイルに比べて、見え方はほぼほぼ同じなのですが属性とコールバック関数の組み合わせに変えたところなど色々と異なる部分がありますので、まずはそちらからご紹介いたします。
❝cutomUI14.xml❞ファイルのコーディング事例
今回の動作確認で使用した❝cutomUI14.xml❞ファイルのコーディング事例をご説明いたします。
※今回は説明のために注釈文が多く含まれていますのであらかじめお含み置きください。
実際のコーディング事例
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="customUI_onLoad" loadImage="customUI_loadImage">
<commands>
<command idMso="Bold" getEnabled="command_getEnabled" onAction="command_onAction"/> <!--enabledとgetEnabledはどちらか-->
</commands>
<ribbon startFromScratch="true"> <!--標準リボンタブを無効化-->
<qat>
<documentControls>
<control idMso="HyperlinkInsert"/>
<control idMso="CalculateNow"/>
<separator id="separator" getVisible="separator_getVisible"/>
<control idMso="Bold"/>
</documentControls>
</qat>
<tabs>
<tab idMso="TabHome" visible="true"/> <!--ホームリボンタブを有効化-->
<tab idMso="TabDeveloper" getVisible="tabDeveloper_getVisible"/> <!--開発リボンタブ有効化 visibleとgetVisibleはどちらか-->
<tab id="CustomTab" label="Custom Tab" insertAfterMso="TabHome"> <!--insertBeforeMsoといづれか-->
<group id="CustomGroup1" label="Custom Group1" getVisible="customGroup1_getVisible">
<button id="Buttonct0" label="Custom Button0" size="large" screentip="リボンリセット" supertip="リボンキャッシュをリセット"
onAction="buttonct0_onAction" getVisible="buttonct0_getVisible"
getImage="buttonct0_getImage" getShowImage="buttonct0_getShowImage"
/> <!--showLabelとgetshowLabelはどちらか。showImage="false"とgetShowImageはOKだがイメージは表示。showImage="true"はNG-->
<button id="Buttonct1" image="IMG01" onAction="buttonct1_onAction"
getLabel="buttonct1_getLabel" getShowLabel="buttonct1_getShowLabel"
getScreentip="buttonct1_getScreentip" getSize="buttonct1_getSize" getSupertip="buttonct1_getSupertip"
/> <!-- imageとgetImage、labelとgetLabel、screentipとgetScreentip、sizeとgetSize、supertipとgetSupertipはどちらか-->
<box id="box1" boxStyle="vertical" getVisible="box1_getVisible">
<button id="button" label="Button" imageMso="ViewFormulaBar" onAction="button_onAction"/>
<checkBox id="checkBox" label="CheckBox" onAction="checkBox_onAction"/> <!--getPressed="checkBox_getPressed"-->
<buttonGroup id="buttonGroup1" getVisible="buttonGroup1_getVisible">
<button id="buttongp1" imageMso="Bold" onAction="buttongp1_onAction"/>
<button id="buttongp2" imageMso="Italic" onAction="buttongp2_onAction"/>
<button id="buttongp3" imageMso="Underline" onAction="buttongp3_onAction"/>
</buttonGroup>
</box>
</group>
<group id="CustomGroup2" label="Custom Group2">
<box id="box2" boxStyle="vertical">
<comboBox id="comboBox" label="Combo Box" invalidateContentOnDrop="true" maxLength="10" sizeString="WWWWWWWWWW"
getItemCount="comboBox_getItemCount" getItemID= "comboBox_getItemID" getItemLabel="comboBox_getItemLabel"
getText="comboBox_getText" onChange="comboBox_onChange">
<!--下記は意味は無いが有ってもエラーにならない。
<item id="item1" label="Item 1"/> <item id="item2" label="Item 2"/> <item id="item3" label="Item 3"/>-->
</comboBox>
<editBox id="editBox" label="Edit Box" maxLength="10" sizeString="WWWWWWWWWW"
getText="editBox_getText" onChange="editBox_onChange"/>
</box>
</group>
<group id="CustomGroup3" label="Custom Group3">
<box id="box3" boxStyle="vertical">
<dropDown id="dropDown" label="DropDown" showItemLabel="true"
getSelectedItemID="dropDown_getSelectedItemID" onAction="dropDown_onAction">
<item id="itemdd1" label="Item 1"/>
<item id="itemdd2" label="Item 2"/>
<item id="itemdd3" label="Item 3"/>
<button id="buttondd" label="ボタン..." onAction="buttondd_onAction"/>
</dropDown>
<menu id="menu1" label="Menu" imageMso="ViewFormulaBar" itemSize="large" description="この機能はNG">
<button id="buttonmn1" label="Button 1" imageMso="FileSave" description="この機能の詳細説明をする"
onAction= "buttonmn1_onAction"/>
<menuSeparator id="menuseparator" getTitle="menuseparator_getTitle"/> <!--titleとgetTitleはどちらか-->
<button id="buttonmn2" label="Button 2" imageMso="Bold" onAction= "buttonmn2_onAction"/>
<button id="buttonmn3" label="Button 3" imageMso="Undo" onAction= "buttonmn3_onAction"/>
</menu>
<toggleButton id="toggleButton" label="Toggle Button" onAction="toggleButton_onAction" getPressed="toggleButton_getPressed"/>
</box>
<dialogBoxLauncher>
<button id="buttondb" screentip="Dialog Box Launcher" onAction="buttondb_onAction"/>
</dialogBoxLauncher>
</group>
<group id="CustomGroup4" label="Custom Group4">
<box id="box4" boxStyle="vertical">
<gallery id="gallery" label="Gallery" size="large" image="IMG02" rows="1" columns="4"
getItemCount="gallery_getItemCount" getItemHeight="gallery_getItemHeight" getItemWidth="gallery_getItemWidth"
getItemID="gallery_getItemID" getItemImage="gallery_getItemImage" getItemLabel="gallery_getItemLabel"
onAction="gallery_onAction"> <!--itemHeightとgetItemHeightはどちらか。 itemWidthとgetItemWidthはどちらか。
showItemImageはfalseでも表示される-->
<!--下記は意味は無いが有ってもエラーにならない。
<item id="itemgy1" imageMso="ActiveXImage"/> <item id="itemgy2" imageMso="ActiveXComboBox"/>
<item id="itemgy3" imageMso="ActiveXListBox"/> <item id="itemgy4" imageMso="ActiveXCheckBox"/>-->
</gallery>
<labelControl id="labelControl" getLabel="labelControl_getLabel"/> <!--labelとgetLabelはどちらか-->
</box>
</group>
<group id="CustomGroup5" label="Custom Group5">
<box id="box5" boxStyle="vertical">
<splitButton id="splitButton" getSize="splitButton_getSize"> <!--sizeとgetSizeはどちらか -->
<button id="buttonsp" image="IMG03" label="Split Button" onAction="buttonsp_onAction"/>
<menu id="menu2">
<button id="buttonsp1" label="Button 1" onAction="buttonsp1_onAction"/>
<button id="buttonsp2" label="Button 2" onAction="buttonsp2_onAction"/>
</menu>
</splitButton>
</box>
</group>
</tab>
</tabs >
</ribbon>
</customUI>
属性をコールバック関数に変えたところ以外での変更点はつぎのようになります。
- 16行目
- 開発リボンタブを有効化するためのtabコントロール(タブ)を追加
※コーディングを確認するためにVisual Basic Editorを頻繁に呼び出す事になるので…
- 開発リボンタブを有効化するためのtabコントロール(タブ)を追加
- 20行目~22行目
- “CustomTab”を初期値の状態に戻すたのbuttonコントロール(タブ)を追加
- idは”Buttonct0″に設定
- 23行目~ 26行目
- buttonコントロール(タブ)の”id”を”CustomButton”から”Buttonct1″に変更
- 28行目
- buttonコントロール(タブ)の”id”と”label”を”button1″から”button”に変更
- 73行目・88行目
- アイコンイメージを変更しました。
※イメージを扱うコールバック関数の動作検証のためです。
- アイコンイメージを変更しました。
今回と前回の”CustomTab”の画面ショットを並べて見ると違いがある事が分かります。


独自アイコンを動的にセットするには
前回、❝customUI❞フォルダーの中にイメージファイルをセットするやり方をご紹介しましたが、コールバック関数を使って動的にイメージを読み込む方法には2つのやり方があります。
❝cutomUI14.xml❞ファイルでアイコンをセットするコントロール(タブ)で次のような設定をします。
※共存する事もできます。
- “getImage”コールバック関数を設定する場合
- 動的にイメージを読み込みます。
- 今回の事例ではIMG00.jpgを”getImage”コールバック関数で動的に読み込みます。
- この場合は”id”を介さずに読み込みます。
- 前回の❝customUI❞フォルダーの中にイメージファイルをセットする時に使った”IMG01″のイメージファイルの拡張子は”.png”でしたが、今回は”.jpg”になります。
- この理由はVBAで使用する”LoadPicture”関数(VBA標準ではないが…)がVBAで扱える標準画像ファイルしか使えないためです。
- 今回の事例ではIMG00.jpgを”getImage”コールバック関数で動的に読み込みます。
- 動的にイメージを読み込みます。
- “image”属性を設定する場合
- 前回の❝customUI❞フォルダーの中にイメージファイルをセットするやり方と同じになるのですが、使用するイメージを”customUI”コントロール(タブ)の”loadImage”コールバック関数で動的にイメージを読み込みます。
- 今回の事例ではIMG02.jpgとIMG03.jpgを”loadImage”コールバック関数で”id”に紐づけて読み込みます。
- ❝cutomUI14.xml❞ファイルのコントロール(タブ)のトロール(タブ)の”image”属性には上記で使用する”id”がユニークになるように命名します。
- “loadImage”コールバック関数は、❝cutomUI14.xml❞ファイルの中に設定されている”image”属性の”id”が❝customUI❞フォルダーにない時に呼ばれます。
※複数(例えば3つ)あればその分(3回)呼ばれます。
- 前回の❝customUI❞フォルダーの中にイメージファイルをセットするやり方と同じになるのですが、使用するイメージを”customUI”コントロール(タブ)の”loadImage”コールバック関数で動的にイメージを読み込みます。
コールバック関数のコーディング事例
続きまして、前節でご紹介した❝cutomUI14.xml❞ファイルのコーディング事例から呼ばれるコールバック関数についてご説明いたします。
なお❝cutomUI14.xml❞ファイルの時と同様に使用を確認するために使った「動かないコールバック関数」についても注釈として残してありますので、お含み置きください。
なお実行する際に、グローバル変数”gb_debug”について下記の注意事項があります。
Option Explicit
Public gr_ribbon As IRibbonUI ' リボンの表示を更新する目的でリボンオブジェクトをセットする
Public gb_check As Boolean 'チェックボックスがチェックされているか?
Public gst_combo As String 'コンボボックスの値を保管
Public gst_edit As String 'エディットボックスの値を保管
Public gst_drop As String 'ドロップダウンの値を保管
Public gb_toggle As Boolean 'トグルボタンの値を保管
Global Const gb_debug As Boolean = True 'TrueにするとDebug.printを有効にする
'【customUI】
Sub customUI_onLoad(ribbon As IRibbonUI)
Set gr_ribbon = ribbon ' リボンの表示を更新する目的でリボンオブジェクトをセットする'
gb_check = False 'onActionではチェックされていない状態で起動されるので初期値はFalse
gst_combo = "Item 2" 'ロード時に初期値を設定する場合
gst_edit = "--ここに入力--" '〃
gst_drop = "itemdd2" '〃
gb_toggle = True '〃
gr_ribbon.ActivateTab ("CustomTab") '指定したタブをアクティベイトする
End Sub
Sub customUI_loadImage(imageId As String, ByRef image)
If gb_debug Then Debug.Print "00=" & "," & imageId & "," & "customUI"
Select Case imageId
Case "IMG02": Set image = LoadPicture(ThisWorkbook.Path & "\IMG02.jpg")
Case "IMG03": Set image = LoadPicture(ThisWorkbook.Path & "\IMG03.jpg")
End Select
End Sub
'【command】
Sub command_getEnabled(control As IRibbonControl, ByRef enabled)
enabled = True 'デフォルト(セットしない時)はfalse
End Sub
Sub command_onAction(control As IRibbonControl, pressed As Boolean, ByRef cancelDefault)
If gb_debug Then Debug.Print "0=" & "," & pressed & "," & cancelDefault & control.id
cancelDefault = False
End Sub
'【control】
'Sub CalculateNow_onAction(control As IRibbonControl) はNG
'【separator】
Sub separator_getVisible(control As IRibbonControl, ByRef visible)
visible = True
End Sub
'【TabDeveloper】
Sub tabDeveloper_getVisible(control As IRibbonControl, ByRef visible)
visible = True 'デフォルト(trueをセットしない)はfalse
End Sub
'【CustomGroup1】
Sub customGroup1_getVisible(control As IRibbonControl, ByRef visible)
visible = True 'デフォルト(trueをセットしない)はfalse
End Sub
'【Buttonct0】
Sub buttonct0_getVisible(control As IRibbonControl, ByRef visible)
visible = True
End Sub
Sub buttonct0_onAction(control As IRibbonControl)
Dim bwk As Variant
' checkboxのチェックは人手でしか変更できないので、初期化はできない。
' gr_ribbon.Invalidate 'リボンキャッシュをクリアーするが、checkboxへの影響が分からないので使用しない
gst_combo = "Item 2" '初期値に戻す
gr_ribbon.InvalidateControl ("comboBox") 'キャッシュをクリアーする事でセットした値が反映される。
gst_edit = "--ここに入力--" '同上
gr_ribbon.InvalidateControl ("editBox") '同上
gst_drop = "itemdd2" '同上
gr_ribbon.InvalidateControl ("dropDown") '同上
gb_toggle = True '同上
gr_ribbon.InvalidateControl ("toggleButton") '同上
End Sub
Sub buttonct0_getImage(control As IRibbonControl, ByRef image)
Set image = LoadPicture(ThisWorkbook.Path & "\IMG00.jpg") 'pngはNG、Setでオブジェクトとして処理
End Sub
Sub buttonct0_getShowImage(control As IRibbonControl, ByRef showImage)
If gb_debug Then Debug.Print "1=" & showImage & "," & control.id
'showImageはデフォルトfalseだが表示されているのでどのように使うか不明
End Sub
'【Buttonct1】
Sub buttonct1_onAction(control As IRibbonControl)
MsgBox "[" & control.id & "]"
End Sub
Sub buttonct1_getLabel(control As IRibbonControl, ByRef label)
label = "Custom Button1"
End Sub
Sub buttonct1_getShowLabel(control As IRibbonControl, ByRef showLabel)
If gb_debug Then Debug.Print "2=" & showLabel & "," & control.id
'showLabelはデフォルトfalseだが表示されているのでどのように使うか不明
End Sub
Sub buttonct1_getScreentip(control As IRibbonControl, ByRef screentip)
screentip = "the screentip"
End Sub
Sub buttonct1_getSize(control As IRibbonControl, ByRef size)
size = RibbonControlSize.RibbonControlSizeLarge 'sizeはlargeではなく列挙値
End Sub
Sub buttonct1_getSupertip(control As IRibbonControl, ByRef screentip)
screentip = "the supertip string" 'パラメータはscreentipでsupertipではないが変数名でしかないので変えてもOK
End Sub
'【box1】
Sub box1_getVisible(control As IRibbonControl, ByRef visible)
If gb_debug Then Debug.Print "3=" & visible & "," & control.id
'visibleはデフォルトfalseだが表示されているのでどのように使うか不明
End Sub
'【Button】
Sub button_onAction(control As IRibbonControl)
gr_ribbon.InvalidateControl ("checkBox") 'キャッシュをクリアーする事でセットした値が反映される。
Select Case gb_check
Case True: MsgBox "チェック(∨)"
Case False: MsgBox "ノーチェック(□)"
End Select
End Sub
'【checkBox】
'onActionとgetPressedはどちらか。getShowLabelはNG
'getPressedはチェックボックスを連続して更新した場合は2度目はコールバック が応しないのでNG
'Sub checkBox_getPressed(control As IRibbonControl, ByRef returnValue)
' gb_check = Not (gb_check)
' returnValue = gb_check 'returnValueに値をセットしないと不整合が起こる場合がある
'End Sub
Sub checkBox_onAction(control As IRibbonControl, pressed As Boolean)
gb_check = Not (gb_check)
If gb_debug Then Debug.Print "4=" & pressed & "," & gb_check & "," & control.id
End Sub
'【buttonGroup1】
Sub buttonGroup1_getVisible(control As IRibbonControl, ByRef visible)
visible = True
End Sub
'【buttongp1】
Sub buttongp1_onAction(control As IRibbonControl)
ActiveCell.Font.Bold = True
End Sub
'【buttongp2】
Sub buttongp2_onAction(control As IRibbonControl)
MsgBox "[" & control.id & "]"
End Sub
'【buttongp3】
Sub buttongp3_onAction(control As IRibbonControl)
MsgBox "[" & control.id & "]"
End Sub
'【comboBox】
Sub comboBox_getItemCount(control As IRibbonControl, ByRef count)
count = 3 '3個のitemを設定
End Sub
Sub comboBox_getItemID(control As IRibbonControl, index As Integer, ByRef id)
If gb_debug Then Debug.Print "5=" & index & "," & control.id
Select Case index 'index値は0から
Case 0: id = "item1"
Case 1: id = "item2"
Case 2: id = "item3"
End Select
End Sub
Sub comboBox_getItemLabel(control As IRibbonControl, index As Integer, ByRef label)
If gb_debug Then Debug.Print "6=" & index & "," & control.id
Select Case index
Case 0: label = "Item 1"
Case 1: label = "Item 2"
Case 2: label = "Item 3"
End Select
End Sub
Sub comboBox_getText(control As IRibbonControl, ByRef text)
If gb_debug Then Debug.Print "7=" & text & "," & control.id
text = gst_combo
End Sub
Sub comboBox_onChange(control As IRibbonControl, text As String)
If gb_debug Then Debug.Print "8=" & gst_combo & "," & text & "," & control.id
gst_combo = text
End Sub
'【editBox】
Sub editBox_getText(control As IRibbonControl, ByRef text)
If gb_debug Then Debug.Print "9=" & text & "," & control.id
text = gst_edit
End Sub
Sub editBox_onChange(control As IRibbonControl, text As String)
If gb_debug Then Debug.Print "A=" & text & "," & control.id
gst_edit = text
End Sub
'【dropDown】
'getSelectedItemIDとgetSelectedItemIndexはどちらか
'Sub dropDown_getSelectedItemIndex(control As IRibbonControl, ByRef index)
Sub dropDown_getSelectedItemID(control As IRibbonControl, ByRef index)
If gb_debug Then Debug.Print "B=" & index & "," & control.id
index = gst_drop
End Sub
Sub dropDown_onAction(control As IRibbonControl, selectedId As String, selectedIndex As Integer)
If gb_debug Then Debug.Print "C=" & selectedId & "," & selectedIndex & "," & control.id
gst_drop = selectedId
End Sub
'【buttondd】
Sub buttondd_onAction(control As IRibbonControl)
MsgBox "[" & control.id & "]"
End Sub
'【menu1】
'Sub menu1_onAction(control As IRibbonControl) はNG
'【buttonmn1】
Sub buttonmn1_onAction(control As IRibbonControl)
MsgBox "[" & control.id & "]"
End Sub
'【menuseparator】
Sub menuseparator_getTitle(control As IRibbonControl, ByRef title)
If gb_debug Then Debug.Print "D=" & title & "," & control.id
title = "操作方法"
End Sub
'【buttonmn2】
Sub buttonmn2_onAction(control As IRibbonControl)
MsgBox "[" & control.id & "]"
End Sub
'【buttonmn3】
Sub buttonmn3_onAction(control As IRibbonControl)
MsgBox "[" & control.id & "]"
End Sub
'【toggleButton】
Sub toggleButton_onAction(control As IRibbonControl, pressed As Boolean)
If gb_debug Then Debug.Print "E=" & pressed & "," & control.id
gb_toggle = pressed
End Sub
Sub toggleButton_getPressed(control As IRibbonControl, ByRef returnValue)
If gb_debug Then Debug.Print "F=" & returnValue & "," & control.id
returnValue = gb_toggle
End Sub
'【buttondb】
Sub buttondb_onAction(control As IRibbonControl)
MsgBox "[" & control.id & "]"
End Sub
'【gallery】
'getItemCount(コールバックを設定しないと以下のコールバックは機能しない
Sub gallery_getItemCount(control As IRibbonControl, ByRef count)
count = 4 '4個のitemを設定
End Sub
Sub gallery_getItemHeight(control As IRibbonControl, ByRef height)
height = 68
End Sub
Sub gallery_getItemWidth(control As IRibbonControl, ByRef width)
width = 88
End Sub
Sub gallery_getItemID(control As IRibbonControl, index As Integer, ByRef id)
Select Case index
Case 0: id = "itemgy1"
Case 1: id = "itemgy2"
Case 2: id = "itemgy3"
Case 3: id = "itemgy4"
End Select
End Sub
Sub gallery_getItemImage(control As IRibbonControl, index As Integer, ByRef image)
Select Case index
Case 0: image = "ActiveXImage"
Case 1: image = "ActiveXComboBox"
Case 2: image = "ActiveXListBox"
Case 3: image = "ActiveXCheckBox"
End Select
End Sub
Sub gallery_getItemLabel(control As IRibbonControl, index As Integer, ByRef label)
Select Case index
Case 0: label = "ActiveXImage"
Case 1: label = "ActiveXComboBox"
Case 2: label = "ActiveXListBox"
Case 3: label = "ActiveXCheckBox"
End Select
End Sub
'getItemScreenTipとgetItemSuperTipはNG
Sub gallery_onAction(control As IRibbonControl, selectedId As String, selectedIndex As Integer)
Select Case selectedIndex
Case 0: MsgBox "[1(" & selectedId & ")]"
Case 1: MsgBox "[2(" & selectedId & ")]"
Case 2: MsgBox "[3(" & selectedId & ")]"
Case 3: MsgBox "[4(" & selectedId & ")]"
End Select
End Sub
'【labelControl】
Sub labelControl_getLabel(control As IRibbonControl, ByRef label)
label = "ラベル" & vbCrLf & "コントロール"
End Sub
'【splitButton】
Sub splitButton_getSize(control As IRibbonControl, ByRef size)
size = RibbonControlSize.RibbonControlSizeRegular '列挙値
End Sub
'【buttonsp】
Sub buttonsp_onAction(control As IRibbonControl)
MsgBox "[" & control.id & "]"
End Sub
'【buttonsp1】
Sub buttonsp1_onAction(control As IRibbonControl)
MsgBox "[" & control.id & "]"
End Sub
'【buttonsp2】
Sub buttonsp2_onAction(control As IRibbonControl)
MsgBox "[" & control.id & "]"
End Sub
| No | ラインNo | コントロール | id/[idMso] | コールバック関数 | debug | 目的 |
| 1 | 10~18 | customUI | なし | onLoad | 初期値をセットし “CustomTab”をアクティベイトする | |
| 2 | 19~25 | loadImage | 00 | 動的イメージを読み込む | ||
| 3 | 27~29 | command | [Bold] | getEnabled | ボタンを有効化する | |
| 4 | 30~33 | onAction | 0 | クリックを受容する | ||
| 5 | 37~39 | separator | separator | getVisible | セパレータを表示させる | |
| 6 | 41~43 | tab | [TabDeveloper] | getVisible | タブを表示させる | |
| 7 | 45~47 | group | CustomGroup1 | getVisible | グループを表示させる | |
| 8 | 49~51 | button | Buttonct0 | getVisible | ボタンを表示させる | |
| 9 | 52~64 | onAction | 初期値に戻す機能を実装 “checkBox”は対象外 | |||
| 10 | 65~67 | getImage | イメージをロードする | |||
| 11 | 68~71 | getShowImage | 1 | [使い方が不明] | ||
| 12 | 72~75 | button | Buttonct1 | onAction | MsgBoxを表示する | |
| 13 | 76~78 | getLabel | ラベル名をセットする | |||
| 14 | 79~82 | getShowLabel | 2 | [使い方が不明] | ||
| 15 | 83~85 | getScreentip | Screentipをセットする | |||
| 16 | 86~88 | getSize | Sizeを列挙型でセットする | |||
| 17 | 89~91 | getSupertip | Supertipをセットする | |||
| 18 | 93~96 | box | box1 | getVisible | 3 | [使い方が不明] |
| 19 | 98~104 | button | button | onAction | checkBoxの状態を判定する | |
| 20 | 112~115 | checkBox | checkBox | onAction | 4 | 値を反転保存する |
| 21 | 117~119 | buttonGroup | buttonGroup1 | getVisible | ボタングループを表示する | |
| 22 | 121~123 | button | buttongp1 | onAction | ActiveCellをBoldにする | |
| 23 | 125~127 | button | buttongp2 | onAction | No.12参照 | |
| 24 | 129~131 | button | buttongp3 | onAction | 〃 | |
| 25 | 133~135 | comboBox | comboBox | getItemCount | itemの数をセットする | |
| 26 | 136~143 | getItemID | 5 | idに代入する値をセットする | ||
| 27 | 144~151 | getItemLabel | 6 | ラベルに代入する値をセットする | ||
| 28 | 152~155 | getText | 7 | 保持された値をセットする | ||
| 29 | 156~159 | onChange | 8 | 入力された値を保持する | ||
| 30 | 161~164 | editBox | editBox | getText | 9 | No.29参照 |
| 31 | 165~168 | onChange | A | No.30参照 | ||
| 32 | 172~175 | dropDown | dropDown | getSelectedItemID | B | 保持された値をセットする |
| 33 | 176~179 | onAction | C | 選択された値を保持する | ||
| 34 | 181~183 | button | buttondd | onAction | No.12参照 | |
| 35 | 187~189 | button | buttonmn1 | onAction | 〃 | |
| 36 | 191~194 | menuSeparator | menuSeparator | getTitle | D | タイトルをセットする |
| 37 | 196~198 | button | buttonmn2 | onAction | No.12参照 | |
| 38 | 200~202 | button | buttonmn3 | onAction | 〃 | |
| 39 | 204~207 | toggleButton | toggleButton | onAction | E | 状態を保持する |
| 40 | 208~211 | getPressed | F | 保持された状態を反映する | ||
| 41 | 213~215 | button | buttondb | onAction | No.12参照 | |
| 42 | 218~220 | gallery | gallery | getItemCount | 表示するアイテム個数をセットする | |
| 43 | 221~223 | getItemHeight | アイテムの高さをセットする | |||
| 44 | 224~226 | getItemWidth | アイテムの幅をセットする | |||
| 45 | 227~234 | getItemID | アイテムのidに代入する値をセットする | |||
| 46 | 235~242 | getItemImage | アイテムのイメージをセットする | |||
| 47 | 243~250 | getItemLabel | アイテムのラベルに代入する値をセットする | |||
| 48 | 251~259 | onAction | 押されたアイテムのMsgBoxを表示する | |||
| 49 | 261~263 | labelControl | labelControl | getLabel | No.14を参照 | |
| 50 | 265~267 | splitButton | splitButton | getSize | No.17を参照 | |
| 51 | 269~271 | button | buttonsp | onAction | No.12参照 | |
| 52 | 273~275 | button | buttonsp1 | onAction | 〃 | |
| 53 | 277~279 | button | buttonsp2 | onAction | 〃 |
まとめ
今回はXML形式でのFulentリボンのコールバック関数について具体的にXMLファイルとVBAのコーディング事例をご紹介しました。
中には使い方が分からないコールバック関数がありましたが、概ね必要になりそうな機能はご紹介できたのではないかと思います…
ただ、第1回の時にまとめた属性一覧とコールバック関数一覧は、今になって思うとあまり意味が無かったように思います。
その理由としては実際に動きを確認して見ると現状では使えない状態になっているものがそれなりの数存在していたためです….
最後に冒頭の章でご紹介した形に必要なフォルダー・ファイルを圧縮してダウンロードできるようにしていますので、ご利用いただければ幸いです。
※アイコンの動的イメージ画像で使用する、❝IMG00.jpg❞・❝IMG02.jpg❞・❝IMG03.jpg❞ファイルを含めています。
- これらのイメージファイルはVBAのコーディングでは作成したマクロ有効ブック”.xlsm”と同じフォルダーに格納されている事にしています。
※実際には次のようにコーディングしています→❝ThisWorkbook.Path & “\IMG00.jpg”❞
| 圧縮ファイルのダウンロード |
|---|
これまで3回に渡りXML形式でのFulentリボンの具体的な使い方をご説明をしてきましたが、今回が最後になります。
以上最後までご一読いただき誠にありがとうございました。


