VBA ComboBox/ListBox/etc.

Flue

Board Regular
Joined
Feb 5, 2009
Messages
106
Alright...this is driving me bonkers.

One workbook(main) builds another(slave). I've added a combo box to the other workbook(slave) and I'm trying to populate it from the Main workbook. I keep getting object errors. "Object does not support this property or method."

This Code:
Code:
Dim cbox As MSForms.ComboBox
Dim ole As OLEObject

Set ole = ActiveSheet.OLEObjects("ComboBox1")
Set cbox = ole.Object

sets ole and cbox to ''''

If I run the code to populate the combobox1 code from the sheet it resides in things work just fine.

Advice?

Thanks.
Brian
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Seems I was trying to manipulate an object with out actually defining an object...who knew.

Found some info and managed to get the comboBox working outside of the sheet VB code.

Code:
Sub MakeCheckBox()
  Dim WS As Excel.Worksheet
  Dim MyChkOLEObj As Excel.OLEObject
  
  Set WS = ActiveSheet
  
  'create checkbox
  Set ShtComboBx = WS.OLEObjects.Add("Forms.ComboBox.1")
With ShtComboBx
    .Left = WS.Range("L3").Left
    .Top = WS.Range("L3").Top
    .Name = "AnsiCombo"
    .Width = "150"
End With

With WS.OLEObjects("AnsiCombo").Object
    .Clear
    .AddItem "item one"
    .AddItem "item 2"
    .AddItem "3"
End With

End Sub

my main mistake was not actually referencing the Object...just the object Name which wasn't working.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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