I made a custom ribbon in Word, that has a ComboBox. I want to populate that ComboBox with items, using a VBA macro. The problem is that seemingly the ComboBox can only hold 1000 items. When I try to put more than 1000 items, I only see an empty ComboBox.
How can I overcome this?
(I am aware that this could be overcome with a userform, but working from the ribbon would be way better.)
Here is my xml code:
<customUI
xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="Ribbon_Load">
<ribbon >
<tabs >
<tab
id="Tab1"
label="CustomTab">
<group id="Group1"
label="CustomGroup" >
<comboBox
id="comboBox1"
label="Elements:"
sizeString="WWWWWWWWWWWWWWWWWWWWWWWW"
getItemID="getElementID"
getItemLabel="getElementLabel"
getItemCount="getElementCount"/>
</group>
</tab >
</tabs >
</ribbon >
</customUI >
and my code in VBA:
Dim myRibbon As IRibbonUI
Sub Ribbon_Load(ribbon As IRibbonUI)
Set myRibbon = ribbon
ribbon.ActivateTab "Tab1"
End Sub
Sub getElementID(control As IRibbonControl, index As Integer, ByRef id)
id = "ID" & index
End Sub
Sub getElementLabel(control As IRibbonControl, index As Integer, ByRef label)
label = "Element " & index
End Sub
Sub getElementCount(control As IRibbonControl, ByRef returnedVal)
returnedVal = 1000
End Sub
If the returnedVal value is 1001 or more, the ComboBox is empty.
Here is the solution:
The limitation you're encountering is a known issue with ComboBoxes in RibbonX. To overcome this limitation, you can implement virtualization. Instead of populating all the items directly into the ComboBox, populate them on demand based on user interaction. When the user interacts with the ComboBox, dynamically load and display the items for that specific interaction. This way, you can effectively work around the 1000-item limitation.
To achieve this, you would need to modify your VBA code to handle ComboBox interactions and populate items dynamically as needed. This approach allows you to maintain a responsive user interface without being constrained by the ComboBox's item limit.