2

I've used fso.FileExists(fullfilepath) many times before, but always with mapped drive letters. I have the reference to Microsoft Scripting Runtime.

In my new situation, many people map the same drive letter to different paths, so I want to use the UNC path.

I keep getting If fso.FileExists(fullfilepath) evaluating to false when I use the UNC path.

If I use the mapped drive letter that I personally use, it evaluates to true - the file IS there, and the path name hasn't changed.

I found some posts from people indicating they had problems when a folder in the path had spaces in the name, and the solution there was to wrap the fullfilepath variable in double-quotes, like

fullfilepath = Chr(34) & fullfilepath & Chr(34) 

but that didn't work either.

I even pasted the paths in instead of using a variable.

This works:

fso.FileExists("S:\pathpart\file.csv")

This does not work:

fso.FileExists("\\\networklocation\pathpart\file.csv")

I tried adding the Microsoft Visual Basic for Applications Extensibility 5.3 reference, it didn't make a difference.

The file is not hidden or read-only.

I'm completely stumped.

Edited to add the path, for clarity: \\corp\sites\abc2001\MIS\Company\Sterling Data\Investments\branch_referrals_13JUN15.csv_13062015.csv

Erik A
  • 31,639
  • 12
  • 42
  • 67
CompanionCube
  • 71
  • 1
  • 2
  • 7
  • I have had much trouble with this - only resolved for me by mapping a drive, i.e. check that it is not mapped and map if not, then use that drive. Lots of code (dll's or classes) to help with your mapping). – Anthony Horne Jun 16 '15 at 20:42
  • 1
    I've never had any problems using FSO and UNC paths. – Tim Williams Jun 16 '15 at 21:37
  • Tell us about the actual path, it may contains characters not valid to FSO. – PatricK Jun 17 '15 at 02:48
  • \\\ is invalid in your example; you need double slashes, is that a question typo? If so what happens if you type the unc into a Run dialog? Does it prompt for credentials? – Alex K. Jun 17 '15 at 09:59
  • sorry - when I originally typed two slashes, the "preview" of my post showed only one, as if the first slash escaped the second. i intended it to show 2 backslashes at the beginning of the unc path. – CompanionCube Jun 17 '15 at 13:00
  • the actual path is just letters, numbers, and a single space: `\\corp\sites\abc2001\MIS\Company\Sterling Data\Investments\branch_referrals_13JUN15.csv_13062015.csv` The only thing I can think of that is left, is the fact that the filename has two dots, is vba seeing the first one as the file-extension indicator? If so what difference does it make? – CompanionCube Jun 17 '15 at 13:05

2 Answers2

1

Ok, it was my own error. I was missing one part of the path, since whenever I navigate to it in Windows Explorer the path shows using my mapped drive - and I missed the folder that it was mapped to when I was copying the path.

The way I discovered it, was that I was thinking I'd have to poll the user's machine to see what mapping they had corresponded to at least the beginning part of the target path - since in order to use the program, they would need to have access to the file it was going to import...

So I went about trying to figure out how to convert a mapped drive letter to a UNC path, then I was going to figure how to loop through all the mapped drives of their machine and compare it to the target path...

If you need to do this, the best explanation and code I found was here: VBA to convert a mapped drive to a UNC path

and when I fed that Function my mapped drive, I got back a result of \\corp\sites\abc2001\loc1shared\ which obviously was the cause of my problems.

CompanionCube
  • 71
  • 1
  • 2
  • 7
0

I'm not able to reproduce that specific error for UNC paths but if the fileexists method is not working for you the Dir method may work for you.

Dir("\\Path\to\File.txt") <> ""
Bee_Riii
  • 814
  • 8
  • 26