0

This is what I have so far, from what I've gather from how others accomplished it.

Set iComboBoxes = New Collection
'Cycling through all controls and gathering all comboboxes
For Each CTRL In UserForm1.Controls
    If TypeName(CTRL) = "ComboBox" Then
        iComboBoxes.Add CTRL
        'Setting onmousedown event handler
        CTRL.OnMouseDown = "=AllComboBoxes_MouseDown(" & CTRL.Name & ")"
    End If
Next CTRL

I get an error saying that the object doesn't support this property or method, on the line where I set the OnMouseDown event handler. I've seen other people do it like this, so I must be missing something.

joshhemphill
  • 492
  • 6
  • 20
  • Where have you seen other people do that? In Access? – Rory Jul 10 '18 at 16:24
  • @Rory Yes, and from what I could tell, the property is the same in Excel according to the documentation. I couldn't see any differences. – joshhemphill Jul 10 '18 at 16:26
  • 1
    The difference is that that doesn't work! You need to use a custom class and `WithEvents` variable(s). There are numerous examples on here (and elsewhere). – Rory Jul 10 '18 at 16:28
  • Possible duplicate of [How to add events to Controls created at runtime in Excel with VBA](https://stackoverflow.com/questions/3014421/how-to-add-events-to-controls-created-at-runtime-in-excel-with-vba) – cyboashu Jul 10 '18 at 17:07

0 Answers0