Preventing file overwriting

  • Thread starter Thread starter TPJoseph
  • Start date Start date
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top