So a new disaster today! I have the following code:
Sub SomeSub()
Call GetFiles("C:\Users\Me\SharePoint\Someone else\Shared_Folder") ', 0)
End Sub
Sub GetFiles(ByVal path As String)
Dim FSO As Object
Set FSO = CreateObject("scripting.filesystemobject")
Dim folder As Object
Set folder = FSO.GetFolder(path)
Dim SubFolder As Object
For Each SubFolder In folder.SubFolders
Call GetFiles(SubFolder.path)
Dim file As Object
For Each file In folder.Files
checkfile = file.Name
If Right(checkfile, 3) = "xls" Then
Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = file.Name
Range("B" & Rows.Count).End(xlUp).Offset(1, 0) = file.path
Range("C" & Rows.Count).End(xlUp).Offset(1, 0) = file.DateLastModified
End If
Next file
Next SubFolder
Set FSO = Nothing
Set folder = Nothing
Set SubFolder = Nothing
Set file = Nothing
End Sub
And it actually works - well sort of. If I look at the results in some cases it gives the same file twice (even though there is only 1 in the folder). More worryingly though it seems to miss complete folders at the same level as the ones it returns. As always I feel like I'm doing something wrong. Am I or is this sort od code hit and miss (although it's been missing the same way all day long).
Bookmarks