I have an excel file with my own ribbon. I have several different elements on the ribbon. Among other things, there is a dropDown list. I would like each item in the list to be displayed with an icon. Unfortunately, so far I haven't been able to achieve this effect.
My customUI14.xml entry looks like this
<dropDown id="Test"
label = "Test dropDown:"
onAction="Test_OnAction"
getItemCount="Test_OnGetItemCount"
getItemID="Test_OnGetItemID"
getItemLabel="Test_OnGetItemLabel"
getItemImage="Test_OnGetItemImage"
getSelectedItemIndex="Test_OnGetSelectedItemIndex"/>
The only thing I've managed to do so far is load an icon from a file
Sub Test_OnGetItemImage(control As IRibbonControl, index As Integer, ByRef returnedVal)
Set returnedVal = LoadPicture("C:\Icons\anyIcon.jpg")
End Sub
However, I would like to avoid loading icons from files. My icons are saved in customUI14.xml but unfortunately I don't know how to use them. I tried this but it doesn't work
Sub Test_OnGetItemImage(control As IRibbonControl, index As Integer, ByRef returnedVal)
returnedVal = "anyIcon"
End Sub
I also tried to place these icons on the sheet and read it as follows but it doesn't work either
Sub Test_OnGetItemImage(control As IRibbonControl, index As Integer, ByRef returnedVal)
set returnedVal = anySheet.Pictures("anyIcon")
End Sub
I also noticed that the LoadPicture function returns a Picture object. The object returned by anySheet.Pictures("anyIcon") has the same type. Yet these are definitely different objects.
Does anyone know how I can read icons from customUI14.xml or from the Pictures collection of the sheet so that they can be loaded as icons for dropdown list items?
To a specific Worksheet, add an ActiveX Image Control (ie Developer > Insert > ActiveX Controls > Image) for each image / icon you want to have available in the DropDown.
Then, add the relevant image / icon to each ActiveX Image Control … select each one in turn then (if necessary right click it and select 'Properties' to make the Properties box appear) click "(None)" next to the 'Picture' property then click the small button with the 3 dots … navigate to and select your image / icon (cannot be .png files but .jpg, .ico, .bmp are all okay). As the image / icon is now loaded to the Worksheet that you are not dependent on external files.
Finally, in your Test_OnGetItemImage
callback, use the value of the index
parameter to drive an If
or Select
statement and get the relevant image / icon using such as
Set returnedVal = ThisWorkbook.Worksheets("Sheet1").OLEObjects("Image1").Object.Picture
replacing "Sheet1" with the name of the Worksheet that all of the ActiveX Image Controls were added to and replacing "Image1" with the name of the ActiveX Image Control that is relevant for the index
.