B
BOB
Hi all,
I posted this question earlier but haven't been able to make it work for me.
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!)
I have been advised to create a file from the command prompt, but it has a
lot of garbage to filter through.
I was also told to write code in this form but have no clue how to use it or
don't know where to run it:
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
Ideally, I would like to be able to take each sub folder name from a folder
and place each name into a cell in excel without having to go through and
delete unwanted things.
If somebody could please give me a step by step approach to solving my
problem, my life would be much better, and it would be very very
appreciated.
Or, if you could, email me at (e-mail address removed) so that I can have a
conversation with you. That tends to simplify things.
Thanks in advance
(Thanks Frank Kabel for the code)
I posted this question earlier but haven't been able to make it work for me.
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!)
I have been advised to create a file from the command prompt, but it has a
lot of garbage to filter through.
I was also told to write code in this form but have no clue how to use it or
don't know where to run it:
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
Ideally, I would like to be able to take each sub folder name from a folder
and place each name into a cell in excel without having to go through and
delete unwanted things.
If somebody could please give me a step by step approach to solving my
problem, my life would be much better, and it would be very very
appreciated.
Or, if you could, email me at (e-mail address removed) so that I can have a
conversation with you. That tends to simplify things.
Thanks in advance
(Thanks Frank Kabel for the code)