How to iterate through all Subdirectories till the last directory in VBA
List all Level SubDirectories using VBA
The following code lists all the directories under c:\Temp
Function GetSubDir(ByVal sDir)
Dim oFS As New FileSystemObject
Dim oDir
Set oDir = oFS.GetFolder(sDir)
For Each oSub In oDir.SubFolders
MsgBox oSub.Path
GetSubDir oSub.Path
Next oSub
End Function
You can call the function like shown below
GetSubDir "C:\Temp\"
The code uses FileSystemObject from Microsoft Scripting RunTime. You need to add reference to this library (see figure below)
- Login or register to post comments
- Feed: vbadb feed
- Original article
