Hello toocold,
Here is a macro that will list the directory your are searching in cell "A1" of the Active Sheet, and all the folder names in it starting at cell "A2".
Sub ListFolders(Optional FolderPath As String)
Dim FolderName As String
Dim R As Long
R = 2
If FolderPath = "" Then FolderPath = CurDir
If Right(FolderPath, 1) <> "\" Then FolderPath = FolderPath & "\"
ActiveSheet.Cells(1, "A") = FolderPath
FolderName = Dir(FolderPath, vbDirectory) ' Retrieve the first entry.
Do While FolderName <> "" ' Start the loop.
'Ignore the current directory and the encompassing directory.
If FolderName <> "." And FolderName <> ".." Then
'Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(FolderPath & FolderName) And vbDirectory) = vbDirectory Then
ActiveSheet.Cells(R, "A") = FolderName
R = R + 1
End If
End If
FolderName = Dir
Loop
End Sub
Sincerely,
Leith Ross
Bookmarks