Hi,
I have a function that returns data from cells in Excel workbooks using ExecuteExcel4Macro
This works fine if I call it from within vba code e.g.
However, if I use =GetCellData("A1") in a cell in the worksheet I just get #VALUE!
Other user defined functions calls in cells work fine.
Any ideas gratefully received!
There are two ways to write error-free programs; only the third one works.
I have a function that returns data from cells in Excel workbooks using ExecuteExcel4Macro
Code:
Function GetCellData(cellRef As String)
Dim wbPath As String
Dim wbName As String
Dim wsName As String
Dim result As String
wbPath = "C:\TEMP\"
wbName = "[Values.xlsx]"
wsName = "Sheet1"
result = "'" & wbPath & wbName & wsName & "'!" & Range(cellRef).Address(True, True, xlR1C1)
GetCellData = ExecuteExcel4Macro(result)
End Function
This works fine if I call it from within vba code e.g.
Code:
Sub TEST()
MsgBox GetCellData("A1")
End Sub
However, if I use =GetCellData("A1") in a cell in the worksheet I just get #VALUE!
Other user defined functions calls in cells work fine.
Any ideas gratefully received!
There are two ways to write error-free programs; only the third one works.