AlexExcel2021
New Member
- Joined
- Feb 23, 2023
- Messages
- 28
- Office Version
- 2021
- Platform
- Windows
I need create ActiveX Combobox dynamically and than fill data to it list.
I try to use this code:
But this reference don't working, line (Set Combo = obj) don't working, I see this log:
LoadPartCombo-start
PartList-23-items
OLEObject
Forms.ComboBox.1
PartCombo
Found1-PartCombo
LoadPartCombo-end
Debugger, of course, don't working too and I don't know how to solve this issue.
I try to use this code:
VBA Code:
Public Sub LoadPartCombo(Manufacturer)
Dim PartList() As String
PartList = GetParts(Manufacturer)
Debug.Print "PartList-" & UBound(PartList) & "-items"
'-----------------------------
Dim Combo As ComboBox
Dim wks As Worksheet
Dim obj As OLEObject
Set wks = ActiveSheet
'Debug.Print wks.OLEObjects.Count
For Each obj In wks.OLEObjects
Debug.Print TypeName(obj)
Debug.Print obj.progID
Debug.Print obj.Name
If obj.progID = "Forms.ComboBox.1" And obj.Name = "PartCombo" Then
Debug.Print "Found1-" & obj.Name
Set Combo = obj
Debug.Print "Found2-" & Combo.Name
Exit For
End If
Next
'-----------------------------
Dim One As Variant
Dim OneArr() As String
For Each One In PartList
If One <> "" Then
Combo.AddItem OneArr(1)
Debug.Print "Add-" & OneArr(1)
End If
Next
Combo.AddItem "--new--"
Debug.Print "Finist-" & Combo.ListCount & "-items-loaded"
End Sub
But this reference don't working, line (Set Combo = obj) don't working, I see this log:
LoadPartCombo-start
PartList-23-items
OLEObject
Forms.ComboBox.1
PartCombo
Found1-PartCombo
LoadPartCombo-end
Debugger, of course, don't working too and I don't know how to solve this issue.