If a file exists .... how do I code this

A

Alison

I want to import a file to replace an existing one. I
code delete the first file - but if it doesnt exist my
macro crashes - how can I say If a file exists then do
the delete etc. and continue with the rest of the import

Grateful for any help

Alison
 
T

Tim

Add an error routine to catch the error and check for the
err code using a Select Case statement. Either do the
import from the error handler, or Resume Next to continue
your original code from the next line (ie. effectively
ignoring the delete method which caused the error)
 
J

Joe Fallon

Public Function FileExists(strPath As String, Optional lngType As Long) As
Boolean
On Error Resume Next
FileExists = Len(Dir(strPath, lngType)) > 0
End Function



If FileExists("some Path") = True Then
'do something
End If
 
Top