In this article I will explain how you can check if a file exists using VBA.
Lets say we have the file “TempFile.xlsx” in the path “D:\Stuff\Business\Temp”:
The code below will check if the file with the full path “D:\Stuff\Business\Temp\Tempfile.xlsx” exists or not. An appropriate message box will be displayed if it does:
The function below returns True if the file specified by the input path exists and false if it doesn’t:
You can download the file and code related to this article from the link below:
- Microsoft MSDN: How to: Determine if a File Exists in Visual Basic
- Excel VBA, Find and List All Files in a Directory and its Subdirectories