Get folders list

  • Thread starter Thread starter Eugene
  • Start date Start date
E

Eugene

Hi, everybody!

Does anyone know, how to get a list of folders with all
subfolders in Excel/VBA? I always get stuck when trying
to write a code for that.

Thanks in advance.
 
Eugene,

Set a reference (in VBA, Tools menu, References item) to
Microsoft Scripting Library and use code like the following:


Sub Start()
Dim FSO As Scripting.FileSystemObject
Dim TopFolder As Scripting.Folder
Set FSO = New Scripting.FileSystemObject
Set TopFolder = FSO.GetFolder("C:\Temp")
DoOneFolder TopFolder
End Sub

Sub DoOneFolder(F As Scripting.Folder)
Dim OneFolder As Scripting.Folder
'
' do something with F
Debug.Print F.Path

For Each OneFolder In F.SubFolders
DoOneFolder OneFolder
Next OneFolder
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Back
Top