View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
isabelle isabelle is offline
external usenet poster
 
Posts: 587
Default Enumerate all subfolders?

hi Robert,

Sub List_SubFolders()
Dim fd As FileDialog, rw As Integer, sfd
Dim oFolder As String, fso As Object

'================================================= ============
'you can replace this part by oFolder = "C:\UserFolders"

Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.AllowMultiSelect = False
.Show
oFolder = .SelectedItems(1)
End With
'================================================= ============

Set fso = CreateObject("Scripting.FileSystemObject")
Set sfoFolder = fso.getfolder(oFolder)

For Each sfd In sfoFolder.SubFolders
rw = rw + 1
Range("A" & rw) = Right(sfd, Len(sfd) - Len(sfoFolder) - 1)
Next
End Sub


--
isabelle



Le 2012-06-20 22:16, Robert Crandal a écrit :
My target folder is "C:\UserFolders". I would like to run a
search of this directory and obtain the names of all subfolders.
Im only searching for folder names, not filenames. Also, this
search should only go one level...I'm only interested in
obtaining the names of the folders that exist in the target
folder "C:\UserFolders".

Can someone show me how to do this? It would be nice if
I could store all the folder names in an array of strings. Or,
it would also be nice if I could just enumerate through
each folder string one at a time using a single string variable.

Thank you!