I am trying to have a macro retrieve information form a closed workbook,
however when i run the function and/or sub it returns #ref! in the cell.
The cell(s) i am calling have information in them, but i still get this error.
any help would be greatly appreciated.
however when i run the function and/or sub it returns #ref! in the cell.
The cell(s) i am calling have information in them, but i still get this error.
any help would be greatly appreciated.
Code:
Private Function GetValue(path, file, sheet, ref)
' 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(ref).Range("A1").Address(, , xlR1C1)
' Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
End Function
Sub PullInSheet1a()
p = "correct path" 'this is correct
f = "correct wrkbk" 'this is correct
s = "Sheet1" 'this is correct
a = "G5" 'correct
ActiveSheet.Range("E20").Value = GetValue(p, f, s, a) 'returns empty?
end sub