array questions

G

Gary Keramidas

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
 
G

Guest

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.
 
G

Guest

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
 
G

Gary Keramidas

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top