エクセル研究室−Excelの基本的な使い方、応用技を紹介

ギャラリーコントロールを使う・その3

ギャラリーコントロールを使う・その3



カスタム ギャラリー コントロールのアイコンのサイズを後から変更する例です。内容的にはその2と同じで、ボタンを押した時にサイズを指定します。テストコマンドというボタンを押せばアイコンサイズが変更されます。


ギャラリーコントロールを使う


ギャラリーコントロールを使う

ギャラリーコントロールではアイコンを設定しないとサイズは指定しても意味がありませんので、フェイスマークを設定しています。


ギャラリーコントロールを使う

XML・customUI.xmlの記述例:



<?xml version="1.0" encoding="Shift_JIS" ?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="MyAddInInitialize">
  <ribbon>
    <tabs>
      <tab id="CustomTab" label="テスト">
        <group id="Group1" label="テストグループ1">
<gallery id="MonthGallery" imageMso="DateAndTimeInsert" label="月選択" columns="3" rows="4" onAction="Module1.Macro1" getItemCount="Module1.Macro2" getItemID="Module1.Macro3" getItemLabel="Module1.Macro4" getItemHeight="Module1.Macro5" getItemWidth="Module1.Macro6" getItemImage="Module1.Macro7" />
          <button id="Button1" imageMso="FileSave" label="テストコマンド1" size="normal" onAction="Module1.Macro8" />
        </group >
      </tab>
    </tabs>
  </ribbon>
</customUI>



VBAの方では

VBA・標準モジュール、Module1の記述例:



Dim MyRibbon As IRibbonUI
Dim I As Variant, X As Double, Y As Double

'動的に更新たい場合は記述する
Sub MyAddInInitialize(Ribbon As IRibbonUI)
    Set MyRibbon = Ribbon
  '設定したいデータを配列に代入
    I = Array("1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月")
End Sub

Sub Macro1(control As IRibbonControl, selectedId As String, selectedIndex As Integer)
    ActiveCell.Value = MonthName(selectedIndex + 1)
End Sub

Sub Macro2(control As IRibbonControl, ByRef count)
    count = UBound(I) + 1
End Sub

Sub Macro3(control As IRibbonControl, index As Integer, ByRef ID)
    ID = "Month" & index
End Sub

Sub Macro4(control As IRibbonControl, index As Integer, ByRef label)
    label = I(index)
End Sub

Sub Macro5(control As IRibbonControl, ByRef height)
    height = Y
End Sub

Sub Macro6(control As IRibbonControl, ByRef width)
    width = X
End Sub

Sub Macro7(control As IRibbonControl, index As Integer, ByRef image)
    image = "HappyFace"
End Sub

Sub Macro8(control As IRibbonControl)
  '特定のサイズにする
    X = 50
    Y = 50
    MyRibbon.InvalidateControl "MonthGallery"
End Sub









リボンのカスタイマイズ方法トップ