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

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try...

VBA Code:
Set Combo = obj.Object

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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