Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default array questions

for some reason, arrays just don't work like i think they should, so i need
some help

i have an array of file names

arr = Array("File1.xls", "File2.xls", "File3.xls")

why doesn't this open them

For i = LBound(arr) To UBound(arr)
Workbooks.Open Filename:=arr(i), ReadOnly:=True, UpdateLinks:=3

arr(i) contains "file1.xls", but i get an error


--


Gary



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 180
Default array questions

Is it the array or the directory? It seems to be working fine as long as
either (1) the files exist in the current directory or (2) I specify the path
in the array of names.

"Gary Keramidas" wrote:

for some reason, arrays just don't work like i think they should, so i need
some help

i have an array of file names

arr = Array("File1.xls", "File2.xls", "File3.xls")

why doesn't this open them

For i = LBound(arr) To UBound(arr)
Workbooks.Open Filename:=arr(i), ReadOnly:=True, UpdateLinks:=3

arr(i) contains "file1.xls", but i get an error


--


Gary




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default array questions

You need to also specify the file path. Here I assumed it is the same as the
workbook running the macro ("ThisWorkbook.Path"). If not, you must specify it
some other way.

Sub TestOpenWBs()
Dim arr As Variant
Dim P As String
Dim i As Integer

arr = Array("File1.xls", "File2.xls", "File3.xls")
P = ThisWorkbook.Path & "\"
For i = LBound(arr) To UBound(arr)
Workbooks.Open P & arr(i)
Next
End Sub

Regards,
Greg


"Gary Keramidas" wrote:

for some reason, arrays just don't work like i think they should, so i need
some help

i have an array of file names

arr = Array("File1.xls", "File2.xls", "File3.xls")

why doesn't this open them

For i = LBound(arr) To UBound(arr)
Workbooks.Open Filename:=arr(i), ReadOnly:=True, UpdateLinks:=3

arr(i) contains "file1.xls", but i get an error


--


Gary




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default array questions

they are in the same folder, so i didn't specify the path. just went back in
because both of you said it seemed to work, and guess what, it did work. i
have no idea.

thanks to both

--


Gary


"Greg Wilson" wrote in message
...
You need to also specify the file path. Here I assumed it is the same as
the
workbook running the macro ("ThisWorkbook.Path"). If not, you must specify
it
some other way.

Sub TestOpenWBs()
Dim arr As Variant
Dim P As String
Dim i As Integer

arr = Array("File1.xls", "File2.xls", "File3.xls")
P = ThisWorkbook.Path & "\"
For i = LBound(arr) To UBound(arr)
Workbooks.Open P & arr(i)
Next
End Sub

Regards,
Greg


"Gary Keramidas" wrote:

for some reason, arrays just don't work like i think they should, so i
need
some help

i have an array of file names

arr = Array("File1.xls", "File2.xls", "File3.xls")

why doesn't this open them

For i = LBound(arr) To UBound(arr)
Workbooks.Open Filename:=arr(i), ReadOnly:=True, UpdateLinks:=3

arr(i) contains "file1.xls", but i get an error


--


Gary






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
Array questions Perico[_2_] Excel Programming 1 July 1st 05 08:22 PM
Array Functions - Two Questions MDW Excel Worksheet Functions 3 January 12th 05 06:54 PM
Array questions Tom Excel Programming 2 November 25th 03 01:06 PM
Listbox and Array questions Stuart[_5_] Excel Programming 4 September 23rd 03 11:04 PM
Array Questions DWTSG Excel Programming 3 July 24th 03 06:53 PM


All times are GMT +1. The time now is 03:21 AM.

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"