I am trying to cycle through a number of worksheets, then listbox controls within each worksheet and populate them with my code. I am using the code below:
Dim sh As Worksheet
Dim obj As OLEObject
Dim lst As MSForms.ListBox
Dim idx As Long
For idx = 1 To ThisWorkbook.Worksheets.Count
Set sh = ThisWorkbook.Worksheets(idx)
For Each obj In sh.OLEObjects
If obj.progID = "Forms.ListBox.1" Then
Set lst = obj
If (lst.Name = "lst1") Then
Call PopulateSimple(lst, "Table1")
End If
End If
Next
Next idx
This seems to fail unfortunately when I set the listbox to the object. Any idea as to how I can achieve looping through all the listboxes in different worksheets and then populating them?
MSForms.ListBoxgives me a compile error, "User defined type not recognized"Dim lst as MSForms.ListBoxintoDim lst as OLEObjectand that is all...lstat all.