' Declarations: Private Declare Function CopyFile Lib "kernel32.dll" Alias "CopyFileA" _
(ByVal lpExistingFileName As String, ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long
' Code: Private Sub cmdCopyFile_Click()
Dim retval As Long
retval = CopyFile("C:\SourceFile.txt", "C:\DestinationFile.txt", 1)
If retval = 0 Then ' failure
MsgBox "Copy failed -- C:\DestinationFile.txt already exists."
Else ' success
MsgBox "Copy succeeded."
End If
End Sub