Reputation: 689
I have a scenario where a user who is not on the domain is trying to open a file that is on the network. Trying to determine if the path exists using the Dir() function. Here is what my code looks like...
If Len(Dir("\\xx\xxxxx\Shared\Virtual Machine\_Testing\Update\", vbDirectory)) > 0 Then Return True
I get the Run-Time error Bad file name or number (error number 52).
Upvotes: 1
Views: 2846
Reputation: 1
Try below steps.
Now run/debug your application. it should work!
Upvotes: -1
Reputation: 8699
For the time-being, if the user doesn't mind mapping a network drive, he could open the file with your code the way it is.
Upvotes: 0
Reputation: 175766
Yep, dir()
on a bad/inaccessible unc causes a runtime error, unlike the behaviour for a local file.
You can either wrap it in an error handler or use the GetFileAttributes
API and look for the directory attribute flag (the built in getattr() won't work for this).
Upvotes: 4