I am developing a custom ribbon extension for Excel, in which a control requires different custom images. I managed to use some images located in my filesystem, but I would like to embed these images inside the .xlsm file. Is it possible to do it and to reference them from the VBA code that updates the image of the control?
For test purposes, this is the XML that defines my custom ribbon:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="ribbonLoaded">
<ribbon>
<tabs>
<tab idMso="TabHome" >
<group id="customGroup1" label="My Group" insertAfterMso="GroupFont">
<button id="customButton1" label="Click Me" size="large" onAction="Macro1" getImage="getButtonImage"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
And this is the macro that change the image of the customButton1
control:
Dim imgIndex As Long
Public Sub getButtonImage(ByVal control As IRibbonControl, ByRef Image)
Select Case control.ID
Case "customButton1"
Set Image = LoadPicture("img" + Trim(Str(imgIndex)) + ".bmp")
imgIndex = (imgIndex + 1) Mod 2
End Select
End Sub
I tried to add the bmp files inside the .xlsm and reference them updating the relationships file (.rels), but I don't know how to reference them from VBA and most important, when I open the file with Excel and save it, they are automatically deleted...
Any help is appreciated!