VBA function to retreive the names of all subfolders within a given folder

  • Thread starter Thread starter Anthony
  • Start date Start date
A

Anthony

How do I write a
VBA function to retreive the names of all subfolders within a given folder?

thx
 
Dim strFolder As String
Dim strSubfolder As String

strFolder = "C:\MyFolder\"
strSubfolder = Dir(strFolder, vbDirectory)
Do While Len(strSubfolder) > 0
If strSubfolder <> "." And strSubfolder <> ".." Then
Debug.Print strFolder & strSubfolder
End If
strSubfolder = Dir()
Loop
 
Excellent!

ty

Douglas J. Steele said:
Dim strFolder As String
Dim strSubfolder As String

strFolder = "C:\MyFolder\"
strSubfolder = Dir(strFolder, vbDirectory)
Do While Len(strSubfolder) > 0
If strSubfolder <> "." And strSubfolder <> ".." Then
Debug.Print strFolder & strSubfolder
End If
strSubfolder = Dir()
Loop
 
Back
Top