Typ unverträglich in UnterordnerCount
17.09.2022 09:04:59
Herbie
es wäre toll, wenn sich jemand mal die Funktion anschauen könnte. Diese Funktion soll Files eines bestimmten Ordners, eines bestimmten Filenamens oder Typs woei Unterordner durchsuchen. Das Durchsuchen nach den Unterordner schlägt fehl, warum auch immer... Es kommt immer eine Fehlermeldung "Typen unverträglich". inm dieser Zeile lngCount = lngCount + countFiles2(objSubF.Path, FileName, SubFolders)
Public Function countFiles2(ByVal strFolder As String, Optional ByVal FileName As String = "", Optional ByVal SubFolders As Boolean = False) As String
Dim objFSO As New Scripting.FileSystemObject
Dim objFolder As Object, objFile As Object, objSubF As Object
Dim lngCount As Long
If Len(strFolder) Then
Set objFolder = objFSO.GetFolder(strFolder)
For Each objFile In objFolder.Files
If objFile.Name Like FileName Then lngCount = lngCount + 1
Next
If SubFolders = True Then
For Each objSubF In objFolder.SubFolders
lngCount = lngCount + countFiles2(objSubF.Path, FileName, SubFolders)
Next
End If
countFiles2 = lngCount & " Datei(en)"
Else
countFiles2 = "k.A."
End If
Set objSubF = Nothing
Set objFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
End Function
Lieben Dank