Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default External data references in a userform control

If I enter an external Excel file cell ref in the Rowsource property of a Listbox it works fine, however if I use the same format to change the Rowsource property I get an error in the VB statement (it goes red).

Can anyone tell me the correct format for
a) addressing a file in the same folder
b) addressing a file in a different folder
c) addressing a file on another drive.

Mike Rea
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default External data references in a userform control

To set a source row from the current activeworkbook use .....

UserForm1.ListBox1.RowSource = "sheet1!a1:a7"

To set it from a closed workbook, you need to open it first get the
rowsource data and close it. I use the following code. Here you can
specify the source drive, folders (directories), source data range etc as
required.
ListData is an array set up to store the rowsource items for loading into
your form control.

Private Sub UserForm_Initialize()
Dim ListData As Variant, i As Integer
Dim SourceWB As Workbook
With Me.ListBox1
.Clear
Application.ScreenUpdating = False
Set SourceWB = Workbooks.Open("C:\filepath\filename.xls", False,
True)
ListItems = SourceWB.Worksheets(1).Range("A1:A3").Value
SourceWB.Close False
Set SourceWB = Nothing
Application.ScreenUpdating = True
ListData = Application.WorksheetFunction.Transpose(ListItems)
For i = 1 To UBound(ListData)
.AddItem ListData(i)
Next i
.ListIndex = -1
End With
End Sub


Cheers
Nigel
"jmikerea" wrote in message
...
If I enter an external Excel file cell ref in the Rowsource property of a

Listbox it works fine, however if I use the same format to change the
Rowsource property I get an error in the VB statement (it goes red).

Can anyone tell me the correct format for
a) addressing a file in the same folder
b) addressing a file in a different folder
c) addressing a file on another drive.

Mike Rea



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default External data references in a userform control

Thanks Nigel. I didn't realise that the external data source had to be open.
I did find an alternative though a bit messy. If I placed the external data cell reference in a spreadsheet cell in the active workbook then addressing that cell connected me to that data.

"Nigel" wrote:

To set a source row from the current activeworkbook use .....

UserForm1.ListBox1.RowSource = "sheet1!a1:a7"

To set it from a closed workbook, you need to open it first get the
rowsource data and close it. I use the following code. Here you can
specify the source drive, folders (directories), source data range etc as
required.
ListData is an array set up to store the rowsource items for loading into
your form control.

Private Sub UserForm_Initialize()
Dim ListData As Variant, i As Integer
Dim SourceWB As Workbook
With Me.ListBox1
.Clear
Application.ScreenUpdating = False
Set SourceWB = Workbooks.Open("C:\filepath\filename.xls", False,
True)
ListItems = SourceWB.Worksheets(1).Range("A1:A3").Value
SourceWB.Close False
Set SourceWB = Nothing
Application.ScreenUpdating = True
ListData = Application.WorksheetFunction.Transpose(ListItems)
For i = 1 To UBound(ListData)
.AddItem ListData(i)
Next i
.ListIndex = -1
End With
End Sub


Cheers
Nigel
"jmikerea" wrote in message
...
If I enter an external Excel file cell ref in the Rowsource property of a

Listbox it works fine, however if I use the same format to change the
Rowsource property I get an error in the VB statement (it goes red).

Can anyone tell me the correct format for
a) addressing a file in the same folder
b) addressing a file in a different folder
c) addressing a file on another drive.

Mike Rea




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract External Data according to a list of references Sarah (OGI) Excel Discussion (Misc queries) 0 April 20th 07 02:20 PM
Sorting Data with External References Herman Merman Excel Discussion (Misc queries) 0 March 26th 06 07:21 AM
External data references in EXCEL 2002 JSPAIN Excel Discussion (Misc queries) 0 April 8th 05 03:25 PM
Cell References and External Data Scott Excel Worksheet Functions 1 April 1st 05 07:31 PM
External References Iain Excel Discussion (Misc queries) 1 February 3rd 05 09:45 AM


All times are GMT +1. The time now is 05:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"