Hello, I have found code generated in this forum to generate a list of files in a specific folder and all its subfolders that have been modified in the past 100 days. However, when running it on the network drive it generates an error and stops. I think the error is caused by permission issues and I would like to exclude the subfolders I cant open. Would I have to specify them, or can the code just skip folders I don't have access to see? any help appreciated. Below is the code i am trying to use
VBA Code:
Sub getfiles()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object, sf
Dim i As Integer, colFolders As New Collection, ws As Worksheet
Set ws = ActiveSheet
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.getfolder("F:\")
colFolders.Add oFolder 'start with this folder
Do While colFolders.Count > 0 'process all folders
Set oFolder = colFolders(1) 'get a folder to process
colFolders.Remove 1 'remove item at index 1
For Each oFile In oFolder.Files
If oFile.DateLastModified > Now - 100 Then
ws.Cells(i + 1, 1) = oFolder.Path
ws.Cells(i + 1, 2) = oFile.Name
ws.Cells(i + 1, 3) = "RO"
ws.Cells(i + 1, 4) = oFile.DateLastModified
ws.Cells(i + 1, 5) = oFile.Size / 1024 ^ 2
i = i + 1
End If
Next oFile
'add any subfolders to the collection for processing
For Each sf In oFolder.subfolders
colFolders.Add sf 'add to collection for processing
Next sf
Loop
End Sub