Public
Sub
CUSS_Daten_zusammenfuehren()
On
Error
GoTo
errExit
Dim
WBQ
As
Workbook
Dim
WBZ
As
Workbook
Dim
varDateien
As
Variant
Dim
lngAnzahl
As
Long
Dim
lngLastQ
As
Long
Dim
fileToOpen
As
Variant
Set
WBZ = ActiveWorkbook
WBZ.Worksheets(
"CUSS_Daten"
).Range(
"A1:K65536"
).ClearContents
varDateien = _
Application.GetOpenFilename(
"Datei (*.xlsx),*.xlsx"
,
False
,
"Bitte gewünschte Datei(en) markieren"
,
False
,
True
)
With
Application
.ScreenUpdating =
False
.EnableEvents =
False
.Calculation = xlCalculationManual
End
With
For
lngAnzahl = LBound(varDateien)
To
UBound(varDateien)
Set
WBQ = Workbooks.Open(Filename:=varDateien(lngAnzahl))
lngLastQ = WBQ.Worksheets(1).Range(
"A65536"
).
End
(xlUp).Row
WBQ.Worksheets(1).Range(
"A1:Z"
& lngLastQ).Copy _
Destination:=WBZ.Worksheets(
"CUSS_Daten"
).Range(
"B"
& WBZ.Worksheets(
"CUSS_Daten"
).Range(
"A65536"
).
End
(xlUp).Row + 1)
WBQ.Close
Next
With
Application
.ScreenUpdating =
True
.EnableEvents =
True
.Calculation = xlCalculationAutomatic
End
With
MsgBox
"Es wurden "
& UBound(varDateien) &
" Dateien zusammengefügt."
, 64
Exit
Sub
errExit:
With
Application
.ScreenUpdating =
True
.EnableEvents =
True
.Calculation = xlCalculationAutomatic
End
With
If
Err.Number = 13
Then
MsgBox
"Es wurde keine Datei ausgewählt"
Else
MsgBox
"Es ist ein Fehler aufgetreten!"
& vbCr _
&
"Fehlernummer: "
& Err.Number & vbCr _
&
"Fehlerbeschreibung: "
& Err.Description
End
If
End
Sub
<span style=
"color: rgb(0, 0, 0); font-family: Arial, Verdana, Geneva, sans-serif; font-size: 14px; line-height: 18px; text-align: left; background-color: rgb(249, 249, 249); "
>Wie schon erwähnt, soll in Spalte A der Name der aktuell geöffneten Datei die unter varDateien eingetragen ist.</span>
<span style=
"color: rgb(0, 0, 0); font-family: Arial, Verdana, Geneva, sans-serif; font-size: 14px; line-height: 18px; text-align: left; background-color: rgb(249, 249, 249); "
>Bisher hatte ich entweder den Erfolg, dass er maximal einmal den Namen in A1 gespeichert hatte oder Excel den Namen von ActiveWorkBook genommen hat, dann aber auch nur in A1</span>
<span style=
"color: rgb(0, 0, 0); font-family: Arial, Verdana, Geneva, sans-serif; font-size: 14px; line-height: 18px; text-align: left; background-color: rgb(249, 249, 249); "
>Irgendwie steh ich gerade auf dem Schlauch wie ich mit ActiveWorkbook.Name das hinbekomme.</span>
<span style=
"color: rgb(0, 0, 0); font-family: Arial, Verdana, Geneva, sans-serif; font-size: 14px; line-height: 18px; text-align: left; background-color: rgb(249, 249, 249); "
>VG JcD</span>