Noson5434
New member
- Local time
- Yesterday, 23:35
- Joined
- Jan 25, 2023
- Messages
- 26
Hi, I'm having trouble checking if a network folder exists.
If a local folder exists then it's all good Ex: (C:\), but if I check a network folder the code takes almost 3 seconds to return False when the folder doesn't exist.
Any suggestions on how to speed up this process?
Thank you.
If a local folder exists then it's all good Ex: (C:\), but if I check a network folder the code takes almost 3 seconds to return False when the folder doesn't exist.
Any suggestions on how to speed up this process?
Thank you.
Code:
Public Sub Test123()
On Error GoTo Err_Handler
Dim blnFound As Boolean
Dim dblStartTime As Double
Dim dblSecondsElapsed As Double
dblStartTime = Timer
blnFound = IsFolder("C:\")
dblSecondsElapsed = Round(Timer - dblStartTime, 2)
Debug.Print "The code ran in " & dblSecondsElapsed & " seconds."
Exit_Err_Handler:
Exit Sub
Err_Handler:
MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description & vbCrLf & "Procedure: Test123", vbCritical + vbOKOnly, "Test123 - Error"
Resume Exit_Err_Handler
End Sub
Private Function IsFolder(ByVal strFolder As String) As Boolean
On Error GoTo Err_Handler
Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
IsFolder = objFSO.FolderExists(strFolder)
Exit_Err_Handler:
If Not objFSO Is Nothing Then Set objFSO = Nothing
Exit Function
Err_Handler:
MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description & vbCrLf & "Procedure: IsFolder", vbCritical + vbOKOnly, "IsFolder - Error"
Resume Exit_Err_Handler
End Function