How to get reference to dynamically created activeX Combobox

AlexExcel2021

New Member
Joined
Feb 23, 2023
Messages
25
Office Version
  1. 2021
Platform
  1. Windows
I need create ActiveX Combobox dynamically and than fill data to it list.

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.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try...

VBA Code:
Set Combo = obj.Object

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,214,902
Messages
6,122,161
Members
449,069
Latest member
msilva74

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top