Preventing file overwriting

T

TPJoseph

I am using the following to check for the presence of a file and if presnet,
prevent it from copying over it. It does not seem to work.

Can someone please advise the proper way to accomplish this? Some example
code would be greatly appreciated.

Thanks.

If Dir("ArchivePathFilenameStr") = "" Then
FileCopy Source:=PathFilenameStr, Destination:=ArchivePathFilenameStr
Else
End If
 
A

AltaEgo

Try this way:

Function FileExists(FName As String) As Boolean
FileExists = (Dir(Fname) > "")
End Function


Use as follows

If FileExists("c:\test\test.xls") Then
'
' MsgBox "File exists"
'
Else
' whatever
End If
 
T

TPJoseph

Thanks.

AltaEgo said:
Try this way:

Function FileExists(FName As String) As Boolean
FileExists = (Dir(Fname) > "")
End Function


Use as follows

If FileExists("c:\test\test.xls") Then
'
' MsgBox "File exists"
'
Else
' whatever
End If
 
Top