AW: Sheet in geschlossener Mappe ?
23.01.2006 14:53:04
Heiko
Hallo Eule,
z.B. so:
Function GetValue(path, file, sheet, ref)
' 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, 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")
' Aufruf z.B. i = GetValue("C:\test", "test1.xls", "Tabelle1", "A1")
' 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 BlattVorhanden()
' Angabe für Tabelle1 dann noch über ne Variable und ne Fehlerroutine rein, dann wäre
' es optimal.
Dim varReturnValue As Variant
varReturnValue = GetValue("C:\Copy", "test.xls", "Tabelle1", "A1")
Select Case CStr(varReturnValue)
Case "File Not Found"
MsgBox "Datei nicht gefunden !", vbCritical
Case "Fehler 2023"
MsgBox "Tabelle1 nicht in Datei vorhanden !", vbCritical
Case Else
MsgBox "Tabelle1 ist in Datei vorhanden !", vbInformation
End Select
End Sub
Gruß Heiko
PS: Rückmeldung wäre nett !