Home » excel » excel – Error When Adding Near 1000 Comboboxes

excel – Error When Adding Near 1000 Comboboxes

Posted by: admin May 14, 2020 Leave a comment

Questions:

I work in the data acquisition field, and our customers needed a way to easily set several settings on up to 256 input channels. Each channel requires 4 combo boxes in order to represent all of the configurable options. Here is a link to what it looks like.

These combo boxes are created in a loop at run time using the following method:

Set obj = Worksheets("Synergy Setup").OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, _
    DisplayAsIcon:=False, Left:=ttl_width + cell_width, Top:=ttl_height, Width:=cell_width2, Height:=cell_height)

Everything works fine up to about ~243 channels (or close to 1000 combo boxes), and then I get the following error:

“Automation Error, Element Not Found, Error -2147319765”

Using MsgBoxes I have confirmed that it is indeed the aforementioned line of code that is causing this error, and it only occurs when I get close to 1000 combo boxes. Also, after this error has occured, everything in my excel file is broken, and I get the continually get the error “Object library invalid or contains references to object definitions that could not be found”. (EDIT: not relevant)

To reiterate, this only happens with a large number of combo boxes. Any thoughts?

EDIT: I wanted to follow up and say that the change to the in-cell combo boxes has not only fixed my issue, but sped up my design 10-fold, and to my surprise, greatly simplified the code as well! Thanks!

How to&Answers:

Perhaps you can think about using in cell drop-down lists instead of the combo boxes.
Like e.g. described here. I think it will show better performance, too.

EDIT:
I captured a code with the macro recorder (I only eliminated the select):

With Range("B:B").Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
    xlBetween, Formula1:="=values_colors"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = ""
    .ShowInput = True
    .ShowError = True
End With

You can still capture the change of values, take a look at the Worksheet_Change Event.