OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 833
- Office Version
- 365
- Platform
- Windows
Am merely trying to see if a file exists. Using Dir(). I confirmed that the path exists using, Dir(sPath, vbDirectory). When wrapping the Dir() in a function to look for the file I use
and get a Run-time error 52 and message that "Bad file name or number".
If I use Dir() directly in my sub there is no error message but Dir does not find my file.
So I know that the path exists and that it ends with a "\". I verified that the file name is correct and that it is in the path that was confirmed to exist.
I tried this code which works (and which will serve my need).
If Dir(sPath & sFileName_Week1) <> "" _
Then bFileExistsWeek1 = True
So curiosity got to me. What am I missing?
VBA Code:
If Dir(psPath, vbNormal) <> "" Then PathExists = True
and get a Run-time error 52 and message that "Bad file name or number".
If I use Dir() directly in my sub there is no error message but Dir does not find my file.
VBA Code:
If Dir(sPath & sFileName_Week1, vbNormal) = "" _
Then bFileExistsWeek1 = False
VBA Code:
If Dir(sPath & sFileName_Week1) = "" _
Then bFileExistsWeek1 = False
So I know that the path exists and that it ends with a "\". I verified that the file name is correct and that it is in the path that was confirmed to exist.
I tried this code which works (and which will serve my need).
If Dir(sPath & sFileName_Week1) <> "" _
Then bFileExistsWeek1 = True
So curiosity got to me. What am I missing?