(Solved) – VBA: Go through Path


i have a problem: I want to build a tool that take information from .xlsm file. These Files are in subfolders. So I need to check all folders in that path and go into the subfolder “eingang”. That subfolder includes many other folders where u can find the .xlsm files.
After that i need to safe some information like “last used” or created date of every file and print it on the worksheet.

So my idea was, to use a “do while” loop to check every mainfolder and check with a new “do while” loop for the subfolder “eingang” etc.

Public Function DateienSuchen(Optional Ordnerpfad As String = "S:Transfercenter", _
                              Optional Dateityp As String, _
                              Optional OhneUnterordner As Boolean) As String()

   Dim idx         As Long
   Dim lngTyp      As Long
   Dim strDir      As String
   Dim strAktDir   As String
   Dim colDir      As New Collection
   Dim arrResult() As String
   lngTyp = Len(Dateityp)
   If Right$(Ordnerpfad, 1) <> "S:Transfercenter" Then
      Ordnerpfad = Ordnerpfad & "S:Transfercenter"
   End If
   colDir.Add Ordnerpfad
   Do While colDir.Count > 0
      strAktDir = colDir.Item(1)
      colDir.Remove 1
      strDir = Dir$(strAktDir, vbDirectory)
      Do While Len(strDir) > 0
         If (strDir <> ".") And (strDir <> "..") Then
         End If

         strDir = Dir$
    For Each strDir In colDir
      strAktDir = colDir.Item(1)
      colDir.Remove 1
      strAktDir = Dir$(strDir & "Eingang")
        Do While strAktDir <> ""

   Set colDir = Nothing
   DateienSuchen = arrResult
End Function

That was my idea to check every folder.

I hope you can help me. When u need more information, feel free to ask.

Leave a Reply

Your email address will not be published. Required fields are marked *