Filling an embedded comobox (ActiveX) on a spreadsheet with a range

RawlinsCross

Active Member
Joined
Sep 9, 2016
Messages
437
Having a bit of an issue with something I thought would be easier (isn't that always how it is). Anyhow, I have spreadsheet with embedded ActiveX comoboxes and I want to fill each with a given range. I have a function that returns the appropriate range (I may have to convert this to a string address???) but I can't even step the code into this function as it fails before hand with the error "Object doesn't support this property". Tried researching but I think I'm getting confused with answers that are based on FORM controls rather than ACTIVEX controls.

VBA Code:
Public Sub InitializeControls()

Dim wSht As Worksheet
Dim ctrl As OLEObject

Set wSht = ThisWorkbook.Worksheets("Form")

For Each ctrl In wSht.OLEObjects
    If ctrl.progID = "Forms.ComboBox.1" Then
        ctrl.ListFillRange = GetControlRange(ctrl.Object.Name)   '<----- Fails here  (also do I need convert this to a string address?)
    End If
Next ctrl

End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
You need the ctrl.Object and yes, you need the address as a string.
 
Upvote 0
That's the kicker, cause I tried it with and without ".Object". The line below as fails with the exact same error.

VBA Code:
ctrl.Object.ListFillRange = GetControlRange(ctrl.Object.Name)
 
Upvote 0
Figure it out... I was so focused on the ".ListFillRange" that I didn't realize that I was failing on the ctrl.Object.Name. The code below works.

VBA Code:
Public Sub InitializeControls()

Dim wSht As Worksheet
Dim ctrl As OLEObject
Set wSht = ThisWorkbook.Worksheets("Form")

For Each ctrl In wSht.OLEObjects
    If ctrl.progID = "Forms.ComboBox.1" Then
        ctrl.ListFillRange = GetControlRange(ctrl.Name).Address  'ctrl.Object.ListFillRange does not work
    End If
Next ctrl

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,574
Messages
6,120,329
Members
448,956
Latest member
Adamsxl

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