I am working through an exercise that uses Dir() to find out whether a file exists in the current directory (i.e. the same directory as the workbook I'm using). The code given - and apparently working in the video example - is like this:
IsThere = (Dir("SomeFile.xlsx") <> "")
When I run this code, IsThere returns False
. I can work around it by using:
IsThere = (Dir(ActiveWorkbook.Path & "\SomeFile.xlsx") <> "")
but I want to know why Dir isn't looking by default in the current directory as expected.
I'm struggling to find any relevant advice on this. Most of the examples I've found of how to use Dir() are with the file path specified so they don't really shed any light on my problem. The closest I've found is this (obsolete) MSDN reference which says that:
To run correctly, the Dir function requires the Read and PathDiscovery flags of FileIOPermission to be granted to the executing code.
Trouble is, I don't really understand the linked advice in there on how to set PathDiscovery to 1.
As for StackOverflow, this is probably the closest to my problem - although this uses a specified path, and I am not referencing a network location. I note that the answer to this question seems to presume that Dir() should work in the way expected i.e. with a simple filename and not a fully specified path.