Sorry, I misread the original message somehow! (I don't know where I got that
idea that you wanted 2 rows.)
Option Explicit
Option Base 0
Sub testme01()
Application.ScreenUpdating = False
Dim myFiles() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String
Dim logWks As Worksheet
Dim oRow As Long
Dim addrCtr As Long
Dim tempVal As Variant
Dim myAddressesToRetrieve As Variant
Dim mySheetsToRetrieve As Variant
myAddressesToRetrieve = Array("a7", "a10", "A3", "D8", "D8", "G11")
mySheetsToRetrieve = Array("sheet1", "sheet1", _
"sheet2", "sheet2", _
"sheet3", "sheet3")
If UBound(myAddressesToRetrieve) <> UBound(mySheetsToRetrieve) Then
MsgBox "design error!"
Exit Sub
End If
'change to point at the folder to check
myPath = "c:\my documents\excel\test"
If Right(myPath, 1) <> "\" Then
myPath = myPath & "\"
End If
myFile = Dir(myPath & "*.xls")
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If
Set logWks = Workbooks.Add(1).Worksheets(1)
'get the list of files
fCtr = 0
Do While myFile <> ""
fCtr = fCtr + 1
ReDim Preserve myFiles(1 To fCtr)
myFiles(fCtr) = myFile
myFile = Dir()
Loop
If fCtr > 0 Then
oRow = 1
For fCtr = LBound(myFiles) To UBound(myFiles)
logWks.Cells(oRow, "A").Resize(2).Value = "'" & myFiles(fCtr)
For addrCtr = LBound(myAddressesToRetrieve) _
To UBound(myAddressesToRetrieve)
tempVal = GetValue(myPath, _
myFiles(fCtr), _
mySheetsToRetrieve(addrCtr), _
myAddressesToRetrieve(addrCtr))
logWks.Cells(oRow, "b").Offset(0, addrCtr).Value = tempVal
Next addrCtr
oRow = oRow + 1
Next fCtr
End If
Application.ScreenUpdating = True
End Sub
Private Function GetValue(path, file, sheet, range_ref)
'from John Walkenbach's site:
'
http://j-walk.com/ss/excel/eee/eee009.txt
'Look for either: GetDataFromClosedFile or GetValue.
'Retrieves a value from a closed workbook
Dim arg As String
'Make sure the file exists
If Right(path, 1) <> "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If
'Create the argument
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(range_ref).Range("A1").Address(, , xlR1C1)
'Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
End Function
Private Function GetValue(path, file, sheet, range_ref)
'from John Walkenbach's site:
'
http://j-walk.com/ss/excel/eee/eee009.txt
'Look for either: GetDataFromClosedFile or GetValue.
'Retrieves a value from a closed workbook
Dim arg As String
'Make sure the file exists
If Right(path, 1) <> "\" Then path = path & "\"
If Dir(path & file) = "" Then
GetValue = "File Not Found"
Exit Function
End If
'Create the argument
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(range_ref).Range("A1").Address(, , xlR1C1)
'Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
End Function