Excel Guides

Checking for the Existence of a File in Excel

There are a few different ways that you can check for the existence of a file in Excel. One way is to use the FILENAME function. This function will return the name of a file, including the path, if it exists. If the file does not exist, it will return an error. Another way to check for the existence of a file is to use the ISFILE function. This function will return TRUE if the file exists and FALSE if it does not exist. You can also use VBA to check for the existence of a file. The following code will return TRUE if the file exists and FALSE if it does not exist:

Dim strFile As String
strFile = "C:\test\test.xls"
If Dir(strFile) <> "" Then
    MsgBox "The file exists."
Else
    MsgBox "The file does not exist."
End If

Move beyond 

Excel

Get started with Causal today.
Build models effortlessly, connect them directly to your data, and share them with interactive dashboards and beautiful visuals.