Does the specified file exist? : File « File Path « VBA / Excel / Access / Word

Does the specified file exist?

Function FileExists(stFile As String) As Boolean
   If Dir(stFile) <> "" Then FileExists = True
End Function

Sub TestForFile()
   Dim myFileName As String
   myFileName = "c:\SalesData1.xls"
   If FileExists(myFileName) Then
      MsgBox myFileName & " exists"
      MsgBox myFileName & " does not exist"
   End If
End Sub


Related examples in the same category

1.Check file existance
2.Gets the file name from the path.
3.List all files under application path
4.Select a folder
5.Select a location containing the files you want to list
6.processes multiple stored files
7.Common File Operations Simplified
8.Use array to store a list of files