Option
Explicit
Sub
Import_mit_Dialog()
Dim
Quelle
As
Object
, Ziel
As
Object
Dim
Datei
As
String
On
Error
GoTo
Fehler
Datei = Application.GetOpenFilename(
"Excel-Dateien(*.xlsx),*xlsx"
)
If
Datei =
"Falsch"
Then
MsgBox
"Keine Datei ausgewählt!"
, ,
"Abbruch"
Exit
Sub
End
If
Workbooks.Open Filename:=Datei
<strong>
Set
Ziel = ThisWorkbook.Worksheets(3)
blatt = Ziel.Range(
"B10"
).Value
Set
Quelle = ActiveWorkbook.Worksheets(blatt)</strong>
Quelle.UsedRange.Copy
Ziel.Cells(1, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=
False
, Transpose:=
False
Application.CutCopyMode =
False
ActiveWorkbook.Close Application.DisplayAlerts =
True
MsgBox
"Import abgeschlossen!"
Set
Quelle =
Nothing
Set
Ziel =
Nothing
Application.DisplayAlerts =
False
Exit
Sub
Fehler:
Set
Quelle =
Nothing
Set
Ziel =
Nothing
MsgBox
"FehlerNr.: "
& Err.Number & vbNewLine & vbNewLine _
&
"Beschreibung: "
& Err.Description _
, vbCritical,
"Fehler"
End
Sub