Import Folder Names From Explorer to Excel

B

BOB

Hi all,

Please help me figure a way to import hundreds
of folder names from Explorer into Excel without doing it individually
(that's a lot of copy-paste!)

Thanks
 
F

Frank Kabel

Hi bob
the following code was poste by Bob Phillips 2 hours ago. It may help
you:
Frank

---------------------------
Here is one way. It outputs the directories to a worksheet, indented as
to
their levels

Dim FSO As Object
Dim cnt As Long
Dim level As Long
Dim arFiles

Sub Folders()
Dim i As Long

Set FSO = CreateObject("Scripting.FileSystemObject")

arFiles = Array()
cnt = 0
level = 1

ReDim arFiles(1, 0)
arFiles(0, 0) = "C:\myTest"
arFiles(1, 0) = level
SelectFiles "C:\myTest"

cnt = 0
For i = LBound(arFiles, 2) To UBound(arFiles, 2)
ActiveSheet.Cells(i + 1, arFiles(1, i)).Value = arFiles(0, i)
Next

End Sub

'----------------------------------------------------------------------
-----
----
Sub SelectFiles(sPath)
'----------------------------------------------------------------------
-----
----
Dim fldr As Object
Dim Folder As Object

Set Folder = FSO.Getfolder(sPath)
level = level + 1
For Each fldr In Folder.Subfolders
cnt = cnt + 1
ReDim Preserve arFiles(1, cnt)
arFiles(0, cnt) = fldr.Name
arFiles(1, cnt) = level
SelectFiles fldr.Path
level = level - 1
Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top