新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Function f_FileCopy(strFN$, strFN2$) As Boolean
If Dir(strFN2) = "" Then
MsgBox "没找到 " & strFN2, vbCritical, "失败"
f_FileCopy = False
Exit Function
End If
If Dir(strFN) <> "" Then Kill strFN
DoEvents
FileCopy strFN2, strFN '重命名
f_FileCopy = True
End Function
Private Sub Command1_Click()
Dim strFN$, strFN2$
strFN = App.Path & "\abc.txt"
strFN2 = strFN & ".bak"
If f_FileCopy(strFN, strFN2) = False Then Exit Sub
MsgBox "拷贝成功", vbInformation, "成功"
End Sub