AW: Excel im Hintergrund öffnen
07.10.2005 14:59:53
Matthias
Hallo Michael,
'VBA Function to Get a Value From a Closed File
'VBA does not include a method to retrieve a value from a closed file. You can, however, take advantage of Excel's ability to work with linked
'files.
'This tip contains a VBA function that retrieves a value from a closed workbook. It does by calling an XLM macro.
'The GetValue Function
'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")
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
Aufruf z.B.
i = GetValue("C:\test", "test1.xls", "Tabelle1", "A1")
Gruß Matthias