VBA UDF (User Defined Function) to determine if a file or folder exists, e.g.

If IsFile(""C:\test.txt"") Then
     Msgbox "File exists"
Else
     Msgbox "File does NOT exist."
End If

VBA Code

Function IsFile(FullFilePath As String) As Boolean
    
    On Error Resume Next
    
    'Return true if file exists
    IsFile = (Dir(FullFilePath) > "")

End Function

Function IsFolder(FolderPath As String) As Boolean

    On Error Resume Next

    If Right(FolderPath, 1) <> "\" Then
        FolderPath = FolderPath & "\"
    End If
    
    'Return true if folder exists
    IsFolder = (Dir(FolderPath, vbDirectory) <> vbNullString)

End Function