Mit Hilfe von Franz und der Herber-CD benutze ich folgenden Code um Daten aus geschlossenen Mappen auszulesen und in eine Tabelle dieser Mappe einzutragen.
Sub Einlesen()
Dim iCounter As Integer, iRow As Integer, i As Integer
Dim sfile As String, sPath As String
iRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
With Application.FileSearch
.LookIn = Range("B1").Value
.FileType = msoFileTypeExcelWorkbooks
.Execute
For iCounter = 1 To .FoundFiles.Count
sfile = Dir(.FoundFiles(iCounter))
sPath = WorksheetFunction.Substitute(.FoundFiles(iCounter), sfile, "")
For i = 6 To 8
With Cells(iRow, i - 5)
.Formula = "='" & sPath & "[" & sfile & "]Kundendaten'!E" & i
.Value = .Value
End With
Next
For i = 14 To 22
With Cells(iRow, i - 10)
.Formula = "='" & sPath & "[" & sfile & "]Kundendaten'!E" & i
.Value = .Value
End With
Next
With Cells(iRow, 13)
.Formula = "='" & sPath & "[" & sfile & "]Kundendaten'!E24"
.Value = .Value
End With
With Cells(iRow, 14)
.Formula = "='" & sPath & "[" & sfile & "]Kundendaten'!E26"
.Value = .Value
End With
With Cells(iRow, 15)
.Formula = "='" & sPath & "[" & sfile & "]Kundendaten'!F6"
.Value = .Value
End With
With Cells(iRow, 16)
.Formula = "='" & sPath & "[" & sfile & "]Info'!C2"
.Value = .Value
End With
iRow = iRow + 1
Next iCounter
End With
End Sub
So weit so gut! Wie kann ich jedoch einen Fehler abfangen wenn eines der Blätter nicht vorhanden ist? Dann soll die Schleife einfach weiter bis zum Ende weiter ausgeführt werden, ohne das eine Fehlermeldung auftaucht. Könnt Ihr mir helfen?
Danke im Voraus.
Gruß
Dieter.K