All Subdirectories
Jim,
You can run into errors ...
1. with the system volume folder - you have to stay away from it
2. with the "If scrFolder.SubFolders.Count 0", it errors if there are no subfolders.
You either have to trap errors at the appropriate point or put a blanket
on error resume next in the code.
Regards,
Jim Cone
"Jim Thomlinson"
wrote in message
FYI, I ran into one very small glitch. I do not have access to one of the
subdirectories. Added this little tidbit of code... Seems to be running
again...
Function DoTheSubFolders(ByRef objFolders As Scripting.Folders, _
ByRef lngN As Long, ByRef strTitle As String)
Dim scrFolder As Scripting.Folder
Dim scrFile As Scripting.File
Dim lngCnt As Long
On Error Goto ErrorHandler
For Each scrFolder In objFolders
For Each scrFile In scrFolder.Files
If scrFile.Name Like strTitle Then
Cells(lngN, 2).Value = scrFile.Path
lngN = lngN + 1
End If
Next 'scrFile
'If there are more sub folders then go back and run function again.
If scrFolder.SubFolders.Count 0 Then
DoTheSubFolders scrFolder.SubFolders, lngN, strTitle
End If
Next 'scrFolder
ErrorHandler:
Set scrFile = Nothing
Set scrFolder = Nothing
End Function--
HTH...
Jim Thomlinson
|