Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Sub folder lList

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

Greg

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Sub folder lList

Bob, worked as expected. Thank you very much

Greg

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default 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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default 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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default 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



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default 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

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pulling pdf files from general folder to specific folder [email protected] Excel Discussion (Misc queries) 2 September 8th 09 09:41 PM
How to decide folder-depth or How to select more folders/subfolders (folder-tree) ? Subteam Excel Discussion (Misc queries) 2 May 7th 06 08:14 PM
Need code to save file to new folder, erase from old folder Ron M. Excel Discussion (Misc queries) 1 February 24th 06 06:02 PM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven Excel Discussion (Misc queries) 1 January 24th 06 03:28 PM
Finding duplicated entries in a llist DeepDarkThought Excel Programming 3 April 30th 04 01:51 PM


All times are GMT +1. The time now is 02:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"