Habe im Netz diese Lösung gefunden! Geht bei mir nicht!
If FindFile(sPath & Cells(i, sSpalte) ) > "" Then
Gibt er aus: Argument ist nicht optional
Option Explicit
Dim FSO, FO, FU, F
Sub Dateien_prüfen()
Dim i As Long ' Zählwert für Reihe
Const sPath As String = "D:\a.noack\Dev\" '"C:\Users\fritz\Documents\Beruf\" 'ANPASSEN
Const sSpalte As Long = 1 'Spalte 1 im Reparaturbuch
'Alle Zellen der angebenen Spalte durchlaufen
For i = 1 To Cells(Rows.Count, sSpalte).End(xlUp).Row
'Ist ein Zelleninhalt vorhanden?
If Cells(i, sSpalte) > "" Then
'Ist die Datei im angegebenen Ordner vorhanden?
If FindFile(sPath, Cells(i, sSpalte) & ".xls") > "" Then
'wenn ja, dann Zeile grau hinterlegen
Cells(i, 1).EntireRow.Interior.ColorIndex = 15
Else
'wenn nein, dann Zeile rot hinterlegen
Cells(i, 1).EntireRow.Interior.ColorIndex = 0
'Cancel = True
End If
End If
Next i
End Sub
Public Function FindFile(sPath As String, sFile As String) As String
Set FSO = CreateObject("Scripting.FileSystemObject")
FindFile = GetSubFolders(sPath, sFile)
End Function
Private Function GetSubFolders(sPath As String, sFile As String) As String
On Error GoTo errHandler
Set FO = FSO.GetFolder(sPath)
Set FU = FO.SubFolders
On Error Resume Next
For Each F In FU
If Dir(F.Path & "\" & sFile) > "" Then
GetSubFolders = F.Path
Exit For
End If
GetSubFolders F.Path, sFile
Next
Exit Function
errHandler:
GetSubFolders = ""
End Function
|