top of page
  • John

Does a file or folder exist?

Updated: Apr 12

NOTE: this post and the code it contains is still valid, however, it has been superseded by the 'Working with files and folders in VBA' post here https://www.thevbahelp.com/post/working-with-files-and-folders-in-vba.


These procedures test whether a path refers to an existing file or folder. Of course, the Dir function that is at the heart of these can be used directly in your own code ... but I find Dir a pain to use, so always wrap it in these handy procedures. You can also use the FileSystemObject to do the same tests.


Also, I don't use Application.PathSeparator (instead using "\") as Application.PathSeparator does not exist in PowerPoint or Outlook and I want my procedures to work from all of the Office applications that I work with.


For a file:



Example usage:



And for a folder:



Example usage:



Limitations: Windows only

0 comments

댓글


bottom of page