Option
Explicit
Sub
Bsp01()
Dim
strPath
As
String
strPath = "D:\Verwaltung\"
Then
strPath = strPath & "\"
Dim
strFile
As
String
Dim
strPart
As
String
Dim
strNr
As
String
strNr = Trim$(ActiveSheet.Range(
"J7"
).Value)
If
strNr =
""
Then
Call
MsgBox(
"Es ist keine Nummer im aktiven Blatt angegeben."
, vbExclamation,
"Vorgang abgebrochen"
)
Exit
Sub
End
If
strFile = Dir$(strPath & strNr &
"_Eingang_*.xlsx"
)
If
strFile =
""
Then
strFile = Dir$(strPath & strNr &
"_Ausgang_*.xlsx"
)
If
strFile =
""
Then
Call
MsgBox(
"Es wurde keine Datei in '"
& strPath &
"' für Nr. '"
& strNr &
"' gefunden."
, _
vbExclamation, _
"Vorgang abgebrochen"
)
Exit
Sub
End
If
Dim
wkbDst
As
Excel.Workbook
Dim
wkbSrc
As
Excel.Workbook
Set
wkbDst = ActiveWorkbook
Set
wkbSrc = Workbooks.Open(strPath & strFile,
ReadOnly
:=
True
)
With
wkbDst.Sheets
Call
wkbSrc.Sheets(Array(
"RW1"
,
"RW3"
,
"RW8"
)).Copy(After:=.Item(.Count))
End
With
Call
wkbSrc.Close
End
Sub