Private Function GetValue(path, file, sheet, ref, v)
path = "C:\Documents and Settings\sdavis\Desktop\Index\XXX\Results"
file = "test.xls"
sheet = "Sheet1"
ref = "A1:R30"
' Retrieves a value from a closed workbook
Dim arg As String
Dim p As Integer
' 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(ref).Cells(v, 2).Address(, , xlR1C1)
' Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
End Function
Sub TestGetValue()
'Declare
Dim v As Integer
'Starting Point
v = 21
'File Location
path = "C:\Documents and Settings\sdavis\Desktop\Index\XXX\Results"
file = "test"
sheet = "Sheet1"
Application.ScreenUpdating = False
For C = 1 To 15
a = Cells(5, C).Address
Cells(5, C) = GetValue(path, file, sheet, a, v)
v = v + 3
Next C
Application.ScreenUpdating = True
End Sub