View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Kieran[_33_] Kieran[_33_] is offline
external usenet poster
 
Posts: 1
Default Macro to enumerate subdirs and files in a directory!

This is not my code. I cannot remeber who authored it - PSC maybe.

Private Sub Path()
On Error GoTo handle
Dim fso, fs, f, x
Set fso = CreateObject("scripting.filesystemobject") 'create
filesystemobject
Set fs = fso.getfolder("c:\") 'gets a hanlde on th
path
' cange as appropriate
Set f = fs.subfolders 'gets a list of al
the folders in the path
Set x = fs.files 'gets a list of al
the files in the path

For Each w In f 'for..next loop
'w this point is the folders in the directory
'for every folder in the list, add it to the subfolder
listbox

' your code here

Next 'loop

For Each v In x
'v lists the files in each folder

' your code here

Next
Exit Sub
handle:
msg = MsgBox("An error has been found. Make sure that the driv
and path exist.", vbCritical, "Error")
End Su

--
Message posted from http://www.ExcelForum.com