How do I set a Listbox's Rowsourse (within Word) to an Excel range?


Posted by Dave Fox on January 20, 2002 10:38 AM

Hi

I've got a form in word with a listbox.
I'm trying to fill the listbox with the values of a range in an excel
spreadsheet called structural sections.xls. In GetExcel I load the
spreadsheet. The highlighted line (>) gives me an error - Could not set the
Row source property. Invalid property value.

Any Ideas on how to sort this problem?

Thanks in advance

Dave

Option Explicit

Public WrkSht As Excel.Worksheet

Sub GetExcel()
Dim Xlobj As Excel.Workbook ' Variable to hold reference to Microsoft
Excel.
Set Xlobj = GetObject("c:\dwgs\documents\structural sections.xls")
Set WrkSht = Xlobj.Sheets("UB")
UserForm1.Show
End Sub

Sub UserForm_Initialize()
Dim xrange As String
xrange = WrkSht.Range("b7:b86").Address(External:=True)
> ListBox1.RowSource = xrange
End Sub

Posted by Dan on January 20, 2002 12:40 PM

Try dropping
.Address(External:=True)

from

xrange = WrkSht.Range("b7:b86").Address(External:=True)




Posted by David Fox on January 21, 2002 6:50 AM

Hi
I've already tried that. Rowsource requires a string not a range.

Cheers
Dave