Option
Explicit
Sub
Beispiel()
Dim
vVal
As
Variant
vVal = GetValue(
"D:\", "
VglMappe.xlsx
", "
Tabelle1
", "
A1")
If
Not
IsError(vVal)
Then
If
ThisWorkbook.Worksheets(1).Range(
"A10"
).Value = vVal
Then
Else
End
If
Else
On
Error
Resume
Next
Err.Raise
CLng
(vVal)
Call
MsgBox(Prompt:=Err.Description & vbNewLine & vbNewLine &
"(Fehler "
& Err.Number &
")"
, _
Title:=
"Fehler"
, _
Buttons:=vbCritical)
On
Error
GoTo
0
End
If
End
Sub
Public
Function
GetValue( _
ByVal
Path
As
String
, _
ByVal
File
As
String
, _
ByVal
Table
As
String
, _
ByVal
CellAddr
As
String
_
)
As
Variant
On
Error
GoTo
ErrHandler
Dim
strRef
As
String
If
Right$(Path, 1) <>
"\" Then Path = Path & "
\"
If
Dir$(Path & File) <>
""
Then
strRef =
"'"
& Path &
"["
& File &
"]"
& Table &
"'!"
& CellAddr
strRef = Application.ConvertFormula(strRef, xlA1, xlR1C1)
GetValue = ExecuteExcel4Macro(strRef)
Else
GetValue = CVErr(53)
End
If
Exit
Function
ErrHandler:
GetValue = CVErr(Err.Number)
End
Function