If you replaced this:
set stations = workbooks("stations.xls").worksheets("Sheet1").range("a1:AL280")
with something like:
set stations = workbooks("C:\somefolder\stations.xls") _
.worksheets("Sheet1").range("a1:AL280")
It won't work.
The workbooks collection expects just the workbook name--no folder, no drive.
That's why the workbook has to be open.
But this would work ok.
Dim StatWkbk as workbook
Dim Stations as range
set statwkbk = workbooks.open(filename:="C:\somefolder\stations.xls")
set stations = statwkbk.worksheets("Sheet1").range("a1:al280")
There are workarounds for retrieving data from other workbooks using VBA,
though. I wouldn't expect any of them to work very quickly with lots of data to
retrieve (or look though).
You can see a way to get a single value here:
Look for GetValue function from John Walkenbach's site:
http://j-walk.com/ss/excel/eee/eee009.txt
or
http://spreadsheetpage.com/index.php..._july_15_1999/
Walter Briscoe wrote:
>
<<snipped>>
> >You could use this syntax, but I find it harder to read:
> >set stations = application.range("'[stations.xls]sheet1'!a1:al280")
> >(no drive, no path--and stations.xls needs to be open)
>
> That is so useful! I found such code did not work with a drive and path.
> Are you able to point at any specification documents to confirm this?
> (My Excel version is 2003 (11.5612.5606))
>
> [snip]
> --
> Walter Briscoe
--
Dave Peterson