0

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.

  • 1
    I think 1000 is a hard limit. You may want to split your items into multiple comboboxes. – Super Symmetry Aug 27 '23 at 09:09
  • 1
    What do these thousend items represent? Have you thought about user experience? – Tom Brunberg Aug 27 '23 at 10:01
  • Those thousand items are names from a database. All names are different, so we can identify the items by their names. I inserted the combobox to get the name suggestions as you type. – eszenyid Aug 27 '23 at 10:24

1 Answers1

-1

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.

  • Good idea, but only works if the user knows what they are looking for. How is that "virtualization"? (just curious) – Super Symmetry Aug 27 '23 at 09:17
  • Good idea, but how do you populate it on demand? I am only aware of the onAction callback function, but it does not solve the issue, since it is only called when the user finishes input. Is it possible to dinamically change the combobox as you type? – eszenyid Aug 27 '23 at 10:03
  • A good answer would include the VBA code to show how to implement your suggestion. – John Korchok Aug 27 '23 at 16:05
  • 3
    ..."now draw the rest of the owl" – Tim Williams Aug 27 '23 at 16:40
  • 1
    The style of this answer looks a lot like that of ChatGPT; also for most/all of your other answers. Note that posting AI-generated content on Stack Overflow is not allowed. – Adrian Mole Aug 29 '23 at 06:45