Grüezi John
John Wirt schrieb am 11.05.2004
Thanks for responding but I shoudl have said that I need a solution n Excel
VBA. That is, I would prefer looking up the value in the closed workbook and
then inserting in the cell in the current workbook as a cell value.
I would prefer some way of using the stored directory path to look up the
cell value in the (closed) workbook, if you can think of anything.
There is indeed a way to get values from closed workbooks; it's an xl4macro
John Walkenbach implemented in a function (works only in VBA *not* in a
cell on a worksheet):
Private Function GetValue(path, file, sheet, range_ref)
'Retrieves a value from a closed workbook
'The GetValue function, listed below takes four arguments:
'path: The drive and path to the closed file (e.g., "d:\files")
'file: The workbook name (e.g., "99budget.xls")
'sheet: The worksheet name (e.g., "Sheet1")
'ref: The cell reference (e.g., "C4")
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
--
Mit freundlichen Grüssen
Thomas Ramel
- MVP für Microsoft-Excel -
[Win 2000Pro SP-4 / xl2000 SP-3]