Public Sub Count_Subfolders_Test()
Dim oFso As Object
Set oFso = CreateObject("Scripting.FileSystemObject")
MsgBox Count_Subfolders(oFso, "F:\temp")
Set oFso = Nothing
End Sub
Private Function Count_Subfolders(oFso As Object, folderPath As String) As Long
Dim Folder As Object, Subfolder As Object
Set Folder = oFso.GetFolder(folderPath)
Count_Subfolders = 0
For Each Subfolder In Folder.subfolder
Count_Subfolders = Count_Subfolders + 1 + Count_Subfolders(oFso, Subfolder.Path)
Next
End Function