antaeusguy
Board Regular
- Joined
- Mar 8, 2010
- Messages
- 81
Hi,
I'm using this code from John Walkenbach Power Programming 2007 page 358 for my Excel 2010 to obtain a cell content from a closed workbook. I checked from the help section that Excel 2010 seems to still support ExecuteExcel4Macro.
This is how I used the function:
Cell A1 = C:\Documents and Settings\admin\Desktop\Testing\
Cell A2 = Book1.xlsx
Cell A3 = Sheet1
Cell A4 = A1
Cell A5 = GetValue(A1, A2, A3, A4)
My cell A5 returned a #VALUE!... it should return the cell content (which I put as "Hello")...
Does anyone have any idea how to fix this function... thanks in advance!
I'm using this code from John Walkenbach Power Programming 2007 page 358 for my Excel 2010 to obtain a cell content from a closed workbook. I checked from the help section that Excel 2010 seems to still support ExecuteExcel4Macro.
This is how I used the function:
Cell A1 = C:\Documents and Settings\admin\Desktop\Testing\
Cell A2 = Book1.xlsx
Cell A3 = Sheet1
Cell A4 = A1
Cell A5 = GetValue(A1, A2, A3, A4)
My cell A5 returned a #VALUE!... it should return the cell content (which I put as "Hello")...
Does anyone have any idea how to fix this function... thanks in advance!
Code:
Private Function GetValue(path, file, sheet, ref)
' Retrieves a value from a closed workbook
Dim arg As String
' Make sure the file exist
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