AW: Tabellenblätter kopieren
20.05.2005 09:39:45
UweD
Hallo
hier ist so ein Freak...
Sub alle_Dateien_Verzeichnis()
Dim strPath$, strExt$, strFile$, TB$
strPath = "C:\Temp\" 'Pfad des Verzeichnisses ggf. anpassen
strExt = "*.xls" 'Dateiextension ggf. anpassen
TB = "DerName" ' das zu kopierende Blatt
If strPath = "" Then
Exit Sub
Else
Application.ScreenUpdating = False
strFile = Dir(strPath & strExt)
Do While Len(strFile) > 0
Workbooks.Open Filename:=strPath & strFile
On Error GoTo Fehler ' wenn Blatt nicht enthalten
Workbooks(strFile).Sheets(TB).Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Sheets(TB).Cells.Copy
Sheets(TB).Cells.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
[A1].Select
'Umbenennen der Blattes
ActiveSheet.Name = TB & " " & Application.Substitute(strFile, ".xls", "")
weiter:
Workbooks(strFile).Close savechanges:=False
strFile = Dir() ' nächste Datei
Loop
Application.ScreenUpdating = True
End If
Exit Sub
Fehler:
If Err.Number = 9 Then
Err.Clear
MsgBox "Gewünschtes Blatt ist in Datei '" & strFile & "' nicht enthalten!"
GoTo weiter
End If
End Sub
Gruß UweD