views:

183

answers:

2

So I have a number of namedRanges in an excel worksheet. I would like to use these to fill in comboboxes on a user form in the same WorkBook.

I have tried:

cboMember.DataSource = Globals.Sheet1.MemberRange.Value

No error is given but the combo is blank. Does anybody have any ideas?

I'm trying to use VSTO for VS 2008 on an excel 2003 work book.

+1  A: 

This is a bit of a guess, but I believe in VBA you can do something like just Range("MyRangeName") to get the named range, so you could try the equivalent of that.

Some ranges in Excel are local to a sheet, some are global to the workbook. If they're local to a sheet then you'll need to prefix with sheet name, e.g. Range("Sheet1!MyRangeName").

Rory
Thanks RoryGlobals.Sheet1.MemberRange.Value does return the correct values in an array but I cannot get my combobox to bind to it. I think I will have to loop through this array to assign the values to the combobox individually, something like cboMember.additem Globals.Sheet1.MemberRange.Value[i]But I was thinking there must ba an easier way.
Dowlers
I think you're right that there's an easier way. How about binding a combobox manually then see how it looks when you inspect it with VBA/debugger?
Rory
+1  A: 

cboMember.RowSource = "NamedRange"

You don't set it to an object. Set it to a string. Excel figures out the rest.

ccampj