TheWennerWoman
Active Member
- Joined
- Aug 1, 2019
- Messages
- 313
- Office Version
- 365
- Platform
- Windows
I have the following (excellent) routine mostly written by @RoryA (thanks, the code works perfectly!) but need a tweak
So someone has deleted one of the folders and the code falls over with a "path not found" error.
How would I amend the above to handle that? In an idea world, I'd have a column named "present?" which returned yes or no depending on whether the path was found.
Thanks in advance as always for your kind help.
VBA Code:
Sub callit()
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim cell As Range
Set cell = ThisWorkbook.Worksheets("Sheet1").Range("A8")
Dim x As Long
Range("B3").ClearContents
Range("A8:C500").ClearContents
For x = 1 To 49
If x = 11 Then x = 20
QueueCount fso, "T:\V1Home\PDF_Poll\AP" & x & "\Test\", cell
' move output cell down four rows
Set cell = cell.Offset(4)
Next x
Range("B3").Value = "Done!"
End Sub
Sub QueueCount(fso As Object, FolderPath As String, outputCell As Range)
Dim folderList
folderList = Array("CREDIT\NONPOP\", "CREDIT\POP\", "INVOICE\NONPOP\", "INVOICE\POP\")
Dim n As Long
For n = LBound(folderList) To UBound(folderList)
Dim strDir As String
strDir = FolderPath & folderList(n)
'strDir = FolderPath & "\" & folderList(n)
Dim objFiles As Object
Set objFiles = fso.GetFolder(strDir).Files
Dim thisFileCount As Long
thisFileCount = objFiles.Count
Dim strTemp As String
strTemp = Dir(strDir & "Thumbs.db", vbHidden + vbSystem)
If strTemp <> "" Then thisFileCount = thisFileCount - 1
lngFileCount = lngFileCount + thisFileCount
outputCell.Offset(n).Resize(, 3).Value = Array(strDir, thisFileCount, Now())
Next n
End Sub
So someone has deleted one of the folders and the code falls over with a "path not found" error.
How would I amend the above to handle that? In an idea world, I'd have a column named "present?" which returned yes or no depending on whether the path was found.
Thanks in advance as always for your kind help.