Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing ComboBox from Workbook Open Event

Status
Not open for further replies.

VBADb

Programmer
Jul 30, 2004
11
US
I'm trying to modify a worksheet combobox within a Workbook Open event module but can't seem to reference it. My code uses SummarySheet.cboProductList to define it but this generates a "Object variable or With block variable not set" error. It seems like it should be simple enough. Any ideas on what I'm missing here?

Thanks, VBADb
 
Unless you have:
SummarySheet

set as the codename or variable name for the sheet then you must reference it like:

sheets("SummarySheet").etc etc

Rgds, Geoff

"Having been erased. the document thjat you are seeking. Must now be retyped"

Please read FAQ222-2244 before you ask a question
 
Try

Sheets("SummarySheet").cboProductList.Value = "What you want displayed"

Sheets("SummarySheet").cboProductList.AddItem ItemToBeAdded
 
First, thanks for taking the time to help me out. The Sheets("sheetname").combobox code works.

But the thing I still don't understand is what's the difference between

Sheets("Summary").combobox.ListRows = x

and

Set MenuBook = Workbooks.Application.ActiveWorkbook
Set SummarySheet = MenuBook.Worksheets("Summary")
SummarySheet.combobox.ListRows = x

the top line works but the bottom code throws an error? Any ideas why that is? I only have one workbook open.
 
I'm a bit confused as I tried similar to your second code

Set MenuBook = Workbooks.Application.ActiveWorkbook
Set SummarySheet = MenuBook.Worksheets("Sheet1")
combobox.AddItem 1
combobox.AddItem 2
combobox.AddItem 3
combobox.AddItem 4
SummarySheet.combobox.ListRows = 2

and it didn't return errors. Do you have any other code that may be effecting this. I am assuming x is an integer in your code?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top