ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Get folders list (https://www.excelbanter.com/excel-programming/284976-get-folders-list.html)

Eugene[_5_]

Get folders list
 
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.




Chip Pearson

Get folders list
 
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


"Eugene" wrote in message
...
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.







All times are GMT +1. The time now is 12:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com