ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sub folder lList (https://www.excelbanter.com/excel-programming/328639-sub-folder-llist.html)

GregR

Sub folder lList
 
I want to copy the names of sub folders from a specific folder to a new
sheet in an existing workbook. I have subfoders under the named
subfolders I want copied, but don't want those, just one branch of a
tree directory so to speak. TIA

Greg


Bob Phillips[_7_]

Sub folder lList
 
Hi Greg,

Try this

Sub FolderListing()
Dim i As Long
Dim oFSO As Object
Dim oFolder As Object
Dim oFldr As Object
Dim sOld As String

Set oFSO = CreateObject("Scripting.FileSystemObject")
i = 2
On Error Resume Next
Worksheets.Add.Name = "Folders"
On Error GoTo 0
ActiveSheet.Cells.ClearContents
Range("A1").Value = "Folder Name"

Set oFolder = oFSO.GetFolder("C:\MyTest")
For Each oFldr In oFolder.subFolders
Cells(i, "A").Value = oFldr.Path
i = i + 1
Next oFldr
Columns(1).AutoFit

End Sub



--
HTH

Bob Phillips

"GregR" wrote in message
oups.com...
I want to copy the names of sub folders from a specific folder to a new
sheet in an existing workbook. I have subfoders under the named
subfolders I want copied, but don't want those, just one branch of a
tree directory so to speak. TIA

Greg




GregR

Sub folder lList
 
Bob, I'll give it a shot as soon as I get to work. I will let you know.
Thanks

Greg


GregR

Sub folder lList
 
Bob, worked as expected. Thank you very much

Greg


Bob Phillips[_7_]

Sub folder lList
 
Thanks Greg, glad it helped.

Regards

Bob

"GregR" wrote in message
oups.com...
Bob, worked as expected. Thank you very much

Greg




GregR

Sub folder lList
 
Bob, is there any way to amend the code to return only the folder name
rather than the whole path and folder?

Greg


Bob Phillips[_7_]

Sub folder lList
 
Hi Greg,

Sure there is. Change the line

Cells(i, "A").Value = oFldr.Path

to

Cells(i, "A").Value = oFldr.Name

--
HTH

Bob Phillips

"GregR" wrote in message
ups.com...
Bob, is there any way to amend the code to return only the folder name
rather than the whole path and folder?

Greg




GregR

Sub folder lList
 
Bob, thanks a million for all your help, not just to me, but to the
countless other posters in the newsgroups

Greg


Bob Phillips[_7_]

Sub folder lList
 
Thank-you Greg, that's very much appreciated.

Regards

Bob

"GregR" wrote in message
oups.com...
Bob, thanks a million for all your help, not just to me, but to the
countless other posters in the newsgroups

Greg





All times are GMT +1. The time now is 03:37 PM.

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