General discussion

Locked

How to check if a File Exists

By mgilbert ·
Hello, I am just starting to get into VBA and have come across the need to write some VB code that checks for a file and then needs to delete that file. I have been reading up on FSO but I must be missing something as I can not get it to work.

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by farzanfar In reply to How to check if a File Ex ...

Public Function FExists(OrigFile As String)
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
FExists = fs.fileexists(OrigFile)
End Function

Collapse -

by mgilbert In reply to

Poster rated this answer.

Collapse -

by farzanfar In reply to How to check if a File Ex ...

Try This :
Public Function FileExists(sFullPath As String) As Boolean
Dim oFile As New Scripting.FileSystemObject
FileExists = oFile.FileExists(sFullPath)
End Function

Collapse -

by mgilbert In reply to

Poster rated this answer.

Collapse -

by salvatore.doria In reply to How to check if a File Ex ...

maybe you have some script blocking application running, so that fso doesn't work. why don't you try this:

Dim FileToDelete as string
FileToDelete="C\path1\subpath2\..\file.ext"
if dir(FileToDelete)<>"" then
Kill FileToDelete
end if

Note: the variable "FileToDelete" contains the complete path of the file you want to delete.

Collapse -

by mgilbert In reply to

Poster rated this answer.

Collapse -

by mgilbert In reply to How to check if a File Ex ...

This question was closed by the author

Back to Web Development Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums