' **********************************************************************
' Modul: Modul5 Typ: Allgemeines Modul
' **********************************************************************
Option Explicit
Sub copySheets()
Dim objFiles() As Object
Dim objWB As Workbook
Dim strPath As String
Dim lngIndex As Long, lngRes As Long
On Error GoTo ErrorHandler
Static CalculationMode As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
CalculationMode = .Calculation
.Calculation = xlManual
.DisplayAlerts = False
End With
strPath = "E:\Forum" 'Start-Verzeichnis - Anpassen!
lngRes = FileSearchINFO(objFiles, strPath, "*.xls", True)
If lngRes <> 0 Then
For lngIndex = 0 To UBound(objFiles)
Set objWB = Workbooks.Open(objFiles(lngIndex).Path)
objWB.Sheets(1).Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = "Rechnung " & lngIndex + 1
objWB.Close False
Next
End If
ErrorHandler:
With Err
If .Number <> 0 Then
MsgBox "Fehler in Prozedur:" & vbTab & "'copySheets'" & vbLf & String(60, "_") & _
vbLf & vbLf & IIf(Erl, "Fehler in Zeile:" & vbTab & Erl & vbLf & vbLf, "") & _
"Fehlernummer:" & vbTab & .Number & vbLf & vbLf & "Beschreibung:" & vbTab & _
.Description & vbLf, vbExclamation + vbMsgBoxSetForeground, _
"VBA - Fehler in Prozedur - copySheets"
.Clear
End If
End With
On Error GoTo 0
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalculationMode
.DisplayAlerts = True
.StatusBar = False
End With
End Sub
Private Function FileSearchINFO(ByRef Files() As Object, ByVal InitialPath As String, Optional ByVal FileName As String = "*", _
Optional ByVal SubFolders As Boolean = False) As Long
'# PARAMETERINFO:
'# Files: Datenfeld zur Ausgabe der Suchergebnisse
'# InitialPath: String der das zu durchsuchende Verzeichnis angibt
'# FileName: String der den gesuchten Dateityp oder Dateinamen enthält (Optional, Standard="*.*" findet alle Dateien)
'# Beispiele: "*.txt" - Findet alle Textdateien
'# "*name*" - Findet alle Dateien mit "name" im Dateinamen
'# "*.avi;*.mpg" - Findet .avi und .mpg Dateien (Dateitypen mit ; trennen)
'# SubFolders: Boolean gibt an, ob Unterordner durchsucht werden sollen (Optional, Standard=False)
Dim fobjFSO As Object, ffsoFolder As Object, ffsoSubFolder As Object, ffsoFile As Object
Dim intC As Integer, varFiles As Variant
Set fobjFSO = CreateObject("Scripting.FileSystemObject")
Set ffsoFolder = fobjFSO.GetFolder(InitialPath)
On Error GoTo ErrExit
If InStr(1, FileName, ";") > 0 Then
varFiles = Split(FileName, ";")
Else
Redim varFiles(0)
varFiles(0) = FileName
End If
For Each ffsoFile In ffsoFolder.Files
If Not ffsoFile Is Nothing Then
For intC = 0 To UBound(varFiles)
If LCase(fobjFSO.GetFileName(ffsoFile)) Like LCase(varFiles(intC)) Then
If IsArray(Files) Then
Redim Preserve Files(UBound(Files) + 1)
Else
Redim Files(0)
End If
Set Files(UBound(Files)) = ffsoFile
Exit For
End If
Next
End If
Next
If SubFolders Then
For Each ffsoSubFolder In ffsoFolder.SubFolders
FileSearchINFO Files, ffsoSubFolder, FileName, SubFolders
Next
End If
If IsArray(Files) Then FileSearchINFO = UBound(Files) + 1
ErrExit:
Set fobjFSO = Nothing
Set ffsoFolder = Nothing
End Function
lngRes = FileSearchINFO(objFiles, strPath, "*.xls", True)
lngRes = FileSearchINFO(objFiles, strPath, "*.xlsx", True)
lngRes = FileSearchINFO(objFiles, strPath, "*.xls*", True)
lngRes = FileSearchINFO(objFiles, strPath, "*.xls", True)
lngRes = FileSearchINFO(objFiles, strPath, "*.xls*", True)
' **********************************************************************
' Modul: Modul5 Typ: Allgemeines Modul
Option Explicit
Sub Löschen()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
If ws.Name Like "RE" & "*" Then
If ThisWorkbook.Sheets.Count = 1 Then
MsgBox "Kann nicht gelöscht werden"
Else
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
End If
Next
End Sub
Sub Erstellen()
Dim objFiles() As Object
Dim objWB As Workbook
Dim strPath As String
Dim lngIndex As Long, lngRes As Long
On Error GoTo ErrorHandler
Static CalculationMode As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
CalculationMode = .Calculation
.Calculation = xlManual
.DisplayAlerts = False
End With
strPath = "C:\Users\Dana\Desktop\Dana\Abrechnung" 'Start-Verzeichnis - Anpassen!
lngRes = FileSearchINFO(objFiles, strPath, "*.xls*", True)
If lngRes <> 0 Then
For lngIndex = 0 To UBound(objFiles)
Set objWB = Workbooks.Open(objFiles(lngIndex).Path)
objWB.Sheets(1).COPY After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = "RE" & lngIndex + 1
objWB.Close False
Next
End If
ErrorHandler:
With Err
If .Number <> 0 Then
MsgBox "Fehler in Prozedur:" & vbTab & "'copySheets'" & vbLf & String(60, "_") & _
vbLf & vbLf & IIf(Erl, "Fehler in Zeile:" & vbTab & Erl & vbLf & vbLf, "") & _
"Fehlernummer:" & vbTab & .Number & vbLf & vbLf & "Beschreibung:" & vbTab & _
.Description & vbLf, vbExclamation + vbMsgBoxSetForeground, _
"VBA - Fehler in Prozedur - copySheets"
.Clear
End If
End With
On Error GoTo 0
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalculationMode
.DisplayAlerts = True
.StatusBar = False
End With
End Sub
Private Function FileSearchINFO(ByRef Files() As Object, ByVal InitialPath As String, Optional _
ByVal FileName As String = "*", _
Optional ByVal SubFolders As Boolean = False) As Long
'# PARAMETERINFO:
'# Files: Datenfeld zur Ausgabe der Suchergebnisse
'# InitialPath: String der das zu durchsuchende Verzeichnis angibt
'# FileName: String der den gesuchten Dateityp oder Dateinamen enthält (Optional, Standard="*.*" _
findet alle Dateien)
'# Beispiele: "*.txt" - Findet alle Textdateien
'# "*name*" - Findet alle Dateien mit "name" im Dateinamen
'# "*.avi;*.mpg" - Findet .avi und .mpg Dateien (Dateitypen mit ; trennen)
'# SubFolders: Boolean gibt an, ob Unterordner durchsucht werden sollen (Optional, Standard= _
False)
Dim fobjFSO As Object, ffsoFolder As Object, ffsoSubFolder As Object, ffsoFile As Object
Dim intC As Integer, varFiles As Variant
Set fobjFSO = CreateObject("Scripting.FileSystemObject")
Set ffsoFolder = fobjFSO.GetFolder(InitialPath)
On Error GoTo ErrExit
If InStr(1, FileName, ";") > 0 Then
varFiles = Split(FileName, ";")
Else
ReDim varFiles(0)
varFiles(0) = FileName
End If
For Each ffsoFile In ffsoFolder.Files
If Not ffsoFile Is Nothing Then
For intC = 0 To UBound(varFiles)
If LCase(fobjFSO.GetFileName(ffsoFile)) Like LCase(varFiles(intC)) Then
If IsArray(Files) Then
ReDim Preserve Files(UBound(Files) + 1)
Else
ReDim Files(0)
End If
Set Files(UBound(Files)) = ffsoFile
Exit For
End If
Next
End If
Next
If SubFolders Then
For Each ffsoSubFolder In ffsoFolder.SubFolders
FileSearchINFO Files, ffsoSubFolder, FileName, SubFolders
Next
End If
If IsArray(Files) Then FileSearchINFO = UBound(Files) + 1
ErrExit:
Set fobjFSO = Nothing
Set ffsoFolder = Nothing
End Function
grüsse john
' **********************************************************************
' Modul: Modul5 Typ: Allgemeines Modul
Option Explicit
Sub Löschen()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
If ws.Name Like "RE" & "*" Then
If ThisWorkbook.Sheets.Count = 1 Then
MsgBox "Kann nicht gelöscht werden"
Else
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
End If
Next
End Sub
Sub Kopieren()
Dim objFiles() As Object
Dim objWB As Workbook
Dim strPath As String
Dim lngIndex As Long, lngRes As Long
On Error GoTo ErrorHandler
Static CalculationMode As Long
With Application
.ScreenUpdating = False
.Application.AskToUpdateLinks = False
.EnableEvents = False
CalculationMode = .Calculation
.Calculation = xlManual
.DisplayAlerts = False
End With
strPath = "C:\Users\Dana\Desktop\Dana\Abrechnung" 'Start-Verzeichnis - Anpassen!
lngRes = FileSearchINFO(objFiles, strPath, "*.xls", True)
If lngRes <> 0 Then
For lngIndex = 0 To UBound(objFiles)
Set objWB = Workbooks.Open(objFiles(lngIndex).Path)
objWB.Sheets(1).COPY After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = "RE" & lngIndex + 1
objWB.Close False
Next
End If
ErrorHandler:
With Err
If .Number <> 0 Then
MsgBox "Fehler in Prozedur:" & vbTab & "'copySheets'" & vbLf & String(60, "_") & _
vbLf & vbLf & IIf(Erl, "Fehler in Zeile:" & vbTab & Erl & vbLf & vbLf, "") & _
"Fehlernummer:" & vbTab & .Number & vbLf & vbLf & "Beschreibung:" & vbTab & _
.Description & vbLf, vbExclamation + vbMsgBoxSetForeground, _
"VBA - Fehler in Prozedur - copySheets"
.Clear
End If
End With
On Error GoTo 0
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalculationMode
.DisplayAlerts = True
.StatusBar = False
End With
End Sub
Private Function FileSearchINFO(ByRef Files() As Object, ByVal InitialPath As String, Optional _
ByVal FileName As String = "*", _
Optional ByVal SubFolders As Boolean = False) As Long
'# PARAMETERINFO:
'# Files: Datenfeld zur Ausgabe der Suchergebnisse
'# InitialPath: String der das zu durchsuchende Verzeichnis angibt
'# FileName: String der den gesuchten Dateityp oder Dateinamen enthält (Optional, Standard="*.*" _
findet alle Dateien)
'# Beispiele: "*.txt" - Findet alle Textdateien
'# "*name*" - Findet alle Dateien mit "name" im Dateinamen
'# "*.avi;*.mpg" - Findet .avi und .mpg Dateien (Dateitypen mit ; trennen)
'# SubFolders: Boolean gibt an, ob Unterordner durchsucht werden sollen (Optional, Standard= _
False)
Dim fobjFSO As Object, ffsoFolder As Object, ffsoSubFolder As Object, ffsoFile As Object
Dim intC As Integer, varFiles As Variant
Set fobjFSO = CreateObject("Scripting.FileSystemObject")
Set ffsoFolder = fobjFSO.GetFolder(InitialPath)
On Error GoTo ErrExit
If InStr(1, FileName, ";") > 0 Then
varFiles = Split(FileName, ";")
Else
ReDim varFiles(0)
varFiles(0) = FileName
End If
For Each ffsoFile In ffsoFolder.Files
If Not ffsoFile Is Nothing Then
For intC = 0 To UBound(varFiles)
If LCase(fobjFSO.GetFileName(ffsoFile)) Like LCase(varFiles(intC)) Then
If IsArray(Files) Then
ReDim Preserve Files(UBound(Files) + 1)
Else
ReDim Files(0)
End If
Set Files(UBound(Files)) = ffsoFile
Exit For
End If
Next
End If
Next
If SubFolders Then
For Each ffsoSubFolder In ffsoFolder.SubFolders
FileSearchINFO Files, ffsoSubFolder, FileName, SubFolders
Next
End If
If IsArray(Files) Then FileSearchINFO = UBound(Files) + 1
ErrExit:
Set fobjFSO = Nothing
Set ffsoFolder = Nothing
End Function
Sub Start()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
If ws.Name Like "RE" & "*" Then
If ThisWorkbook.Sheets.Count = 1 Then
MsgBox "Kann nicht gelöscht werden"
Else
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
End If
Next
Call Kopieren
End Sub
Hab es jetzt ein wenig angepasst das wenn ich es Starte er mir die RE Blätter löscht und dann das Kopieren anfängt (hier habe ich auch in deinem Makro geändert das er keine Fehlermeldung gibt wenn es externe verlinkung vorhanden sind), oder aber ich auswählen kann das nur die RE gelöscht werden!
If lngRes <> 0 Then
For lngIndex = 0 To UBound(objFiles)
If Not lngIndex Like "Datei1*" Or lngIndex Like "Datei2*" Then '"Mappe*"
If Not SourceFolder.Path & "\" & lngIndex = ThisWorkbook.FullName Then Workbooks.Open SourceFolder.Path & "\" & lngIndex
Set objWB = Workbooks.Open(objFiles(lngIndex).Path)
objWB.Sheets(1).COPY After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = "RE" & lngIndex + 1
objWB.Close False
Next
End If
grüsse John
Sub Kopieren()
Dim objFiles() As Object
Dim objWB As Workbook
Dim strPath As String
Dim lngIndex As Long, lngRes As Long
On Error GoTo ErrorHandler
Static CalculationMode As Long
With Application
.ScreenUpdating = False
.Application.AskToUpdateLinks = False
.EnableEvents = False
CalculationMode = .Calculation
.Calculation = xlManual
.DisplayAlerts = False
End With
strPath = "C:\Users\Dana\Desktop\Dana\Abrechnung" 'Start-Verzeichnis - Anpassen!
lngRes = FileSearchINFO(objFiles, strPath, "*.xls", True)
With ThisWorkbook
If lngRes <> 0 Then
For lngIndex = 0 To UBound(objFiles)
If Not objFiles(lngIndex).Name Like "Datei1*" Or objFiles(lngIndex).Name Like "Datei2*" Then '"Mappe*"
If Not objFiles(lngIndex).Path = .FullName Then
Set objWB = Workbooks.Open(objFiles(lngIndex).Path)
objWB.Sheets(1).Copy After:=.Sheets(.Sheets.Count)
.Sheets(.Sheets.Count).Name = "RE" & lngIndex + 1
objWB.Close False
End If
End If
Next
End If
End With
ErrorHandler:
With Err
If .Number <> 0 Then
MsgBox "Fehler in Prozedur:" & vbTab & "'copySheets'" & vbLf & String(60, "_") & _
vbLf & vbLf & IIf(Erl, "Fehler in Zeile:" & vbTab & Erl & vbLf & vbLf, "") & _
"Fehlernummer:" & vbTab & .Number & vbLf & vbLf & "Beschreibung:" & vbTab & _
.Description & vbLf, vbExclamation + vbMsgBoxSetForeground, _
"VBA - Fehler in Prozedur - copySheets"
.Clear
End If
End With
On Error GoTo 0
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalculationMode
.DisplayAlerts = True
.StatusBar = False
End With
End Sub
' **********************************************************************
' Modul: Modul5 Typ: Allgemeines Modul
' **********************************************************************
Option Explicit
Sub copySheets()
Dim objFiles() As Object
Dim objWB As Workbook
Dim strPath As String
Dim lngIndex As Long, lngRes As Long
On Error GoTo ErrorHandler
Static CalculationMode As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
CalculationMode = .Calculation
.Calculation = xlManual
.DisplayAlerts = False
End With
strPath = "E:\Forum" 'Start-Verzeichnis - Anpassen!
lngRes = FileSearchINFO(objFiles, strPath, "*.xls", True)
If lngRes <> 0 Then
For lngIndex = 0 To UBound(objFiles)
Set objWB = Workbooks.Open(objFiles(lngIndex).Path)
objWB.Sheets(1).Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = "Rechnung " & lngIndex + 1
objWB.Close False
Next
End If
ErrorHandler:
With Err
If .Number <> 0 Then
MsgBox "Fehler in Prozedur:" & vbTab & "'copySheets'" & vbLf & String(60, "_") & _
vbLf & vbLf & IIf(Erl, "Fehler in Zeile:" & vbTab & Erl & vbLf & vbLf, "") & _
"Fehlernummer:" & vbTab & .Number & vbLf & vbLf & "Beschreibung:" & vbTab & _
.Description & vbLf, vbExclamation + vbMsgBoxSetForeground, _
"VBA - Fehler in Prozedur - copySheets"
.Clear
End If
End With
On Error GoTo 0
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalculationMode
.DisplayAlerts = True
.StatusBar = False
End With
End Sub
Private Function FileSearchINFO(ByRef Files() As Object, ByVal InitialPath As String, Optional ByVal FileName As String = "*", _
Optional ByVal SubFolders As Boolean = False) As Long
'# PARAMETERINFO:
'# Files: Datenfeld zur Ausgabe der Suchergebnisse
'# InitialPath: String der das zu durchsuchende Verzeichnis angibt
'# FileName: String der den gesuchten Dateityp oder Dateinamen enthält (Optional, Standard="*.*" findet alle Dateien)
'# Beispiele: "*.txt" - Findet alle Textdateien
'# "*name*" - Findet alle Dateien mit "name" im Dateinamen
'# "*.avi;*.mpg" - Findet .avi und .mpg Dateien (Dateitypen mit ; trennen)
'# SubFolders: Boolean gibt an, ob Unterordner durchsucht werden sollen (Optional, Standard=False)
Dim fobjFSO As Object, ffsoFolder As Object, ffsoSubFolder As Object, ffsoFile As Object
Dim intC As Integer, varFiles As Variant
Set fobjFSO = CreateObject("Scripting.FileSystemObject")
Set ffsoFolder = fobjFSO.GetFolder(InitialPath)
On Error GoTo ErrExit
If InStr(1, FileName, ";") > 0 Then
varFiles = Split(FileName, ";")
Else
Redim varFiles(0)
varFiles(0) = FileName
End If
For Each ffsoFile In ffsoFolder.Files
If Not ffsoFile Is Nothing Then
For intC = 0 To UBound(varFiles)
If LCase(fobjFSO.GetFileName(ffsoFile)) Like LCase(varFiles(intC)) Then
If IsArray(Files) Then
Redim Preserve Files(UBound(Files) + 1)
Else
Redim Files(0)
End If
Set Files(UBound(Files)) = ffsoFile
Exit For
End If
Next
End If
Next
If SubFolders Then
For Each ffsoSubFolder In ffsoFolder.SubFolders
FileSearchINFO Files, ffsoSubFolder, FileName, SubFolders
Next
End If
If IsArray(Files) Then FileSearchINFO = UBound(Files) + 1
ErrExit:
Set fobjFSO = Nothing
Set ffsoFolder = Nothing
End Function
lngRes = FileSearchINFO(objFiles, strPath, "*.xls", True)
lngRes = FileSearchINFO(objFiles, strPath, "*.xlsx", True)
lngRes = FileSearchINFO(objFiles, strPath, "*.xls*", True)
lngRes = FileSearchINFO(objFiles, strPath, "*.xls", True)
lngRes = FileSearchINFO(objFiles, strPath, "*.xls*", True)
' **********************************************************************
' Modul: Modul5 Typ: Allgemeines Modul
Option Explicit
Sub Löschen()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
If ws.Name Like "RE" & "*" Then
If ThisWorkbook.Sheets.Count = 1 Then
MsgBox "Kann nicht gelöscht werden"
Else
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
End If
Next
End Sub
Sub Erstellen()
Dim objFiles() As Object
Dim objWB As Workbook
Dim strPath As String
Dim lngIndex As Long, lngRes As Long
On Error GoTo ErrorHandler
Static CalculationMode As Long
With Application
.ScreenUpdating = False
.EnableEvents = False
CalculationMode = .Calculation
.Calculation = xlManual
.DisplayAlerts = False
End With
strPath = "C:\Users\Dana\Desktop\Dana\Abrechnung" 'Start-Verzeichnis - Anpassen!
lngRes = FileSearchINFO(objFiles, strPath, "*.xls*", True)
If lngRes <> 0 Then
For lngIndex = 0 To UBound(objFiles)
Set objWB = Workbooks.Open(objFiles(lngIndex).Path)
objWB.Sheets(1).COPY After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = "RE" & lngIndex + 1
objWB.Close False
Next
End If
ErrorHandler:
With Err
If .Number <> 0 Then
MsgBox "Fehler in Prozedur:" & vbTab & "'copySheets'" & vbLf & String(60, "_") & _
vbLf & vbLf & IIf(Erl, "Fehler in Zeile:" & vbTab & Erl & vbLf & vbLf, "") & _
"Fehlernummer:" & vbTab & .Number & vbLf & vbLf & "Beschreibung:" & vbTab & _
.Description & vbLf, vbExclamation + vbMsgBoxSetForeground, _
"VBA - Fehler in Prozedur - copySheets"
.Clear
End If
End With
On Error GoTo 0
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalculationMode
.DisplayAlerts = True
.StatusBar = False
End With
End Sub
Private Function FileSearchINFO(ByRef Files() As Object, ByVal InitialPath As String, Optional _
ByVal FileName As String = "*", _
Optional ByVal SubFolders As Boolean = False) As Long
'# PARAMETERINFO:
'# Files: Datenfeld zur Ausgabe der Suchergebnisse
'# InitialPath: String der das zu durchsuchende Verzeichnis angibt
'# FileName: String der den gesuchten Dateityp oder Dateinamen enthält (Optional, Standard="*.*" _
findet alle Dateien)
'# Beispiele: "*.txt" - Findet alle Textdateien
'# "*name*" - Findet alle Dateien mit "name" im Dateinamen
'# "*.avi;*.mpg" - Findet .avi und .mpg Dateien (Dateitypen mit ; trennen)
'# SubFolders: Boolean gibt an, ob Unterordner durchsucht werden sollen (Optional, Standard= _
False)
Dim fobjFSO As Object, ffsoFolder As Object, ffsoSubFolder As Object, ffsoFile As Object
Dim intC As Integer, varFiles As Variant
Set fobjFSO = CreateObject("Scripting.FileSystemObject")
Set ffsoFolder = fobjFSO.GetFolder(InitialPath)
On Error GoTo ErrExit
If InStr(1, FileName, ";") > 0 Then
varFiles = Split(FileName, ";")
Else
ReDim varFiles(0)
varFiles(0) = FileName
End If
For Each ffsoFile In ffsoFolder.Files
If Not ffsoFile Is Nothing Then
For intC = 0 To UBound(varFiles)
If LCase(fobjFSO.GetFileName(ffsoFile)) Like LCase(varFiles(intC)) Then
If IsArray(Files) Then
ReDim Preserve Files(UBound(Files) + 1)
Else
ReDim Files(0)
End If
Set Files(UBound(Files)) = ffsoFile
Exit For
End If
Next
End If
Next
If SubFolders Then
For Each ffsoSubFolder In ffsoFolder.SubFolders
FileSearchINFO Files, ffsoSubFolder, FileName, SubFolders
Next
End If
If IsArray(Files) Then FileSearchINFO = UBound(Files) + 1
ErrExit:
Set fobjFSO = Nothing
Set ffsoFolder = Nothing
End Function
grüsse john
' **********************************************************************
' Modul: Modul5 Typ: Allgemeines Modul
Option Explicit
Sub Löschen()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
If ws.Name Like "RE" & "*" Then
If ThisWorkbook.Sheets.Count = 1 Then
MsgBox "Kann nicht gelöscht werden"
Else
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
End If
Next
End Sub
Sub Kopieren()
Dim objFiles() As Object
Dim objWB As Workbook
Dim strPath As String
Dim lngIndex As Long, lngRes As Long
On Error GoTo ErrorHandler
Static CalculationMode As Long
With Application
.ScreenUpdating = False
.Application.AskToUpdateLinks = False
.EnableEvents = False
CalculationMode = .Calculation
.Calculation = xlManual
.DisplayAlerts = False
End With
strPath = "C:\Users\Dana\Desktop\Dana\Abrechnung" 'Start-Verzeichnis - Anpassen!
lngRes = FileSearchINFO(objFiles, strPath, "*.xls", True)
If lngRes <> 0 Then
For lngIndex = 0 To UBound(objFiles)
Set objWB = Workbooks.Open(objFiles(lngIndex).Path)
objWB.Sheets(1).COPY After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = "RE" & lngIndex + 1
objWB.Close False
Next
End If
ErrorHandler:
With Err
If .Number <> 0 Then
MsgBox "Fehler in Prozedur:" & vbTab & "'copySheets'" & vbLf & String(60, "_") & _
vbLf & vbLf & IIf(Erl, "Fehler in Zeile:" & vbTab & Erl & vbLf & vbLf, "") & _
"Fehlernummer:" & vbTab & .Number & vbLf & vbLf & "Beschreibung:" & vbTab & _
.Description & vbLf, vbExclamation + vbMsgBoxSetForeground, _
"VBA - Fehler in Prozedur - copySheets"
.Clear
End If
End With
On Error GoTo 0
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalculationMode
.DisplayAlerts = True
.StatusBar = False
End With
End Sub
Private Function FileSearchINFO(ByRef Files() As Object, ByVal InitialPath As String, Optional _
ByVal FileName As String = "*", _
Optional ByVal SubFolders As Boolean = False) As Long
'# PARAMETERINFO:
'# Files: Datenfeld zur Ausgabe der Suchergebnisse
'# InitialPath: String der das zu durchsuchende Verzeichnis angibt
'# FileName: String der den gesuchten Dateityp oder Dateinamen enthält (Optional, Standard="*.*" _
findet alle Dateien)
'# Beispiele: "*.txt" - Findet alle Textdateien
'# "*name*" - Findet alle Dateien mit "name" im Dateinamen
'# "*.avi;*.mpg" - Findet .avi und .mpg Dateien (Dateitypen mit ; trennen)
'# SubFolders: Boolean gibt an, ob Unterordner durchsucht werden sollen (Optional, Standard= _
False)
Dim fobjFSO As Object, ffsoFolder As Object, ffsoSubFolder As Object, ffsoFile As Object
Dim intC As Integer, varFiles As Variant
Set fobjFSO = CreateObject("Scripting.FileSystemObject")
Set ffsoFolder = fobjFSO.GetFolder(InitialPath)
On Error GoTo ErrExit
If InStr(1, FileName, ";") > 0 Then
varFiles = Split(FileName, ";")
Else
ReDim varFiles(0)
varFiles(0) = FileName
End If
For Each ffsoFile In ffsoFolder.Files
If Not ffsoFile Is Nothing Then
For intC = 0 To UBound(varFiles)
If LCase(fobjFSO.GetFileName(ffsoFile)) Like LCase(varFiles(intC)) Then
If IsArray(Files) Then
ReDim Preserve Files(UBound(Files) + 1)
Else
ReDim Files(0)
End If
Set Files(UBound(Files)) = ffsoFile
Exit For
End If
Next
End If
Next
If SubFolders Then
For Each ffsoSubFolder In ffsoFolder.SubFolders
FileSearchINFO Files, ffsoSubFolder, FileName, SubFolders
Next
End If
If IsArray(Files) Then FileSearchINFO = UBound(Files) + 1
ErrExit:
Set fobjFSO = Nothing
Set ffsoFolder = Nothing
End Function
Sub Start()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
If ws.Name Like "RE" & "*" Then
If ThisWorkbook.Sheets.Count = 1 Then
MsgBox "Kann nicht gelöscht werden"
Else
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
End If
Next
Call Kopieren
End Sub
Hab es jetzt ein wenig angepasst das wenn ich es Starte er mir die RE Blätter löscht und dann das Kopieren anfängt (hier habe ich auch in deinem Makro geändert das er keine Fehlermeldung gibt wenn es externe verlinkung vorhanden sind), oder aber ich auswählen kann das nur die RE gelöscht werden!
If lngRes <> 0 Then
For lngIndex = 0 To UBound(objFiles)
If Not lngIndex Like "Datei1*" Or lngIndex Like "Datei2*" Then '"Mappe*"
If Not SourceFolder.Path & "\" & lngIndex = ThisWorkbook.FullName Then Workbooks.Open SourceFolder.Path & "\" & lngIndex
Set objWB = Workbooks.Open(objFiles(lngIndex).Path)
objWB.Sheets(1).COPY After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count).Name = "RE" & lngIndex + 1
objWB.Close False
Next
End If
grüsse John
Sub Kopieren()
Dim objFiles() As Object
Dim objWB As Workbook
Dim strPath As String
Dim lngIndex As Long, lngRes As Long
On Error GoTo ErrorHandler
Static CalculationMode As Long
With Application
.ScreenUpdating = False
.Application.AskToUpdateLinks = False
.EnableEvents = False
CalculationMode = .Calculation
.Calculation = xlManual
.DisplayAlerts = False
End With
strPath = "C:\Users\Dana\Desktop\Dana\Abrechnung" 'Start-Verzeichnis - Anpassen!
lngRes = FileSearchINFO(objFiles, strPath, "*.xls", True)
With ThisWorkbook
If lngRes <> 0 Then
For lngIndex = 0 To UBound(objFiles)
If Not objFiles(lngIndex).Name Like "Datei1*" Or objFiles(lngIndex).Name Like "Datei2*" Then '"Mappe*"
If Not objFiles(lngIndex).Path = .FullName Then
Set objWB = Workbooks.Open(objFiles(lngIndex).Path)
objWB.Sheets(1).Copy After:=.Sheets(.Sheets.Count)
.Sheets(.Sheets.Count).Name = "RE" & lngIndex + 1
objWB.Close False
End If
End If
Next
End If
End With
ErrorHandler:
With Err
If .Number <> 0 Then
MsgBox "Fehler in Prozedur:" & vbTab & "'copySheets'" & vbLf & String(60, "_") & _
vbLf & vbLf & IIf(Erl, "Fehler in Zeile:" & vbTab & Erl & vbLf & vbLf, "") & _
"Fehlernummer:" & vbTab & .Number & vbLf & vbLf & "Beschreibung:" & vbTab & _
.Description & vbLf, vbExclamation + vbMsgBoxSetForeground, _
"VBA - Fehler in Prozedur - copySheets"
.Clear
End If
End With
On Error GoTo 0
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = CalculationMode
.DisplayAlerts = True
.StatusBar = False
End With
End Sub