AW: Zugriff auf geschlossene Datei
11.06.2008 16:44:59
Hajo_Zi
Hallo Melissa,
Option Explicit
' von Alf Herber Forum
' https://www.herber.de/ _
forum/archiv/52to56/t52834.htm#52840
Sub TestGetValue()
Dim p As String
Dim f As String
Dim s As String
Dim r As String
p = "L:\Eigene Dateien\Hajo\"
f = "Adresse.xlsm"
s = "Adresse"
r = "B4"
' bennanter Bereich ergänzung von Nikhil Milo
' r = "Heinze"
MsgBox GetValue(p, f, s, r)
Worksheets("Tabelle1").Range("A1") = GetValue(p, f, s, r)
End Sub
Public 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)
' bennanter Bereich ergänzung von Nikhil Milo
' arg = "'" & path & "[" & file & "]" & sheet & "'!" & ref
' Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
End Function
Public Function Start(path, file, sheet, ref)
Worksheets("Tabelle1").Range("A1") = GetValue(path, file, sheet, ref)
Start = Worksheets("Tabelle1").Range("A1")
End Function