The above error is encountered when trying to loop through sub-folders on a mapped network drive.
The function works as expected when applied to the local C:\ DRIVE.
Any ideas how I can overcome this problem?
The error occurrs on the following line: For Each subfolder In folder.SubFolders
Function FindFolder(ByVal strStartFolder As String, ByVal strFolderNamePattern As String) As String
Dim fso As Object, folder As Object, subfolder As Object
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set folder = fso.GetFolder(strStartFolder)
On Error GoTo 0
If folder Is Nothing Then
FindFolder = ""
Exit Function
End If
'Check the current folder first
If FolderMatchesPattern(folder.Name, strFolderNamePattern) Then
FindFolder = folder.Path
Exit Function
End If
'Recursively search subfolders
For Each subfolder In folder.SubFolders
FindFolder = FindFolder(subfolder.Path, strFolderNamePattern)
If FindFolder <> "" Then
Exit Function
End If
Next subfolder
FindFolder = ""
Set fso = Nothing
Set folder = Nothing
Set subfolder = Nothing
End Function