How to check if a file exists in Excel-VBA

Today we will discuss different ways to check if a file exists in Excel-VBA.

It is possible to use the following custom function which takes a full path to a file (like "C:/Folder/file.doc") as an input and outputs boolean TRUE if the file exists and FALSE if it doesn't.

Function CheckFileExists(strFileName As String)

Dim strFileExists As String
Dim filestatus As Boolean
    strFileExists = Dir(strFileName)
   If strFileExists = "" Then
        filestatus = False
    Else
        filestatus = True
    End If
    CheckFileExists = filestatus
End Function