Returns the boolean value True if the named file exists.
- Syntax
-
If FileExists(FileName) Then ...
FileName - Required text argument that specifies the name of the file.
Use a complete path specification either absolute or relative.
Source
Function FileExists(ByVal FileName As String) As Boolean
Dim hFile As Long
hFile = FreeFile
On Error GoTo Trap
Open FileName For Input As hFile
On Error GoTo 0
Close hFile
FileExists = True
Exit Function
Trap:
If Err.Number <> 53 Then 'File not found.
Err.Raise Err.Number, , Err.Description
End If
FileExists = True
Exit Function
End Function
|