OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 833
- Office Version
- 365
- Platform
- Windows
I have what is probably a trivial question
In my sub, I have this code that tells me whether a file exists. It works.
BUT I wanted to use a function instead of that code in my sub. It seems odd to me that when that same syntax used in my sub is used in the function I get an error #52, Bad file name or number.
Function call
Function
What am I missing?
In my sub, I have this code that tells me whether a file exists. It works.
VBA Code:
If Dir(sPath & sFileToProcessName, vbNormal) <> "" _
Then
BUT I wanted to use a function instead of that code in my sub. It seems odd to me that when that same syntax used in my sub is used in the function I get an error #52, Bad file name or number.
Function call
VBA Code:
If PathExists(sPath & sFileToProcessName, True) _
Then
Function
VBA Code:
Function PathExists(psPath As String, Optional bFile As Boolean = False) As Boolean
PathExists = False
Debug.Print "in function path = " & psPath
If Right(psPath, 1) <> "\" Then psPath = psPath & "\"
If bFile _
Then
If Dir(psPath, vbNormal) <> "" Then PathExists = True
Else
If Dir(psPath, vbDirectory) <> "" Then PathExists = True
End If
End Function
What am I missing?