The FileSystemObject VBA FileExists function returns True if the file exists otherwise will return False.
VBA FileSystemObject Methods
- BuildPath
- CopyFile
- CopyFolder
- CreateFolder
- CreateTextFile
- DeleteFile
- DeleteFolder
- DriveExists
- FileExists
- FolderExists
- GetAbsolutePathName
- GetBaseName
- GetDrive
- GetDriveName
- GetExtensionName
- GetFile
- GetFileName
- GetFolder
- GetParentFolderName
- GetSpecialFolder
- GetTempName
- MoveFile
- MoveFolder
- OpenTextFile
VBA FileExists Syntax
fso.FileExits( filepath )
filepath
A string representing path to the file.
VBA FileExists Examples
Below examples assume file “C:\Src\Hello.txt” exists and no other files exist in the folder “C:\Src”.
Set fso = CreateObject("Scripting.FileSystemObject") Debug.Print fso.FileExists("C:\Src\Hello.txt") 'Result: True Debug.Print fso.FileExists("C:\Src\Goodbye.txt") 'Result: False