Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I make this recursive? 1

Status
Not open for further replies.

rockfish12

Technical User
Feb 12, 2002
31
0
0
US
How can I make the following code not only return the subfolders within a folder, but also return subfolders within subfolders, ad infinitum?
______________________________________________________
Sub LoopDeLoop(strPath As String)

Dim objFSO As FileSystemObject
Dim objFolder As Folder
Dim objSubFldr As Folder

Set objFSO = New FileSystemObject
Set objFolder = objFSO.GetFolder(strPath)

For Each objSubFldr In objFolder.SubFolders
Debug.Print objSubFldr.Name
Next objSubFldr

End Sub
 
Add 1 line as shown below

Sub LoopDeLoop(strPath As String)

Dim objFSO As FileSystemObject
Dim objFolder As Folder
Dim objSubFldr As Folder

Set objFSO = New FileSystemObject
Set objFolder = objFSO.GetFolder(strPath)

For Each objSubFldr In objFolder.SubFolders
Debug.Print objSubFldr.Name
LoopDeLoop objSubFldr.Path '<----------Here

Next objSubFldr

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top