新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Sub Command1_Click()
Dim sourceFile As String
Dim destinationFile As String
' 设置源文件路径
sourceFile = "C:\SourceFolder\SourceFile.txt"
' 设置目标文件路径
destinationFile = "D:\DestinationFolder\DestinationFile.txt"
On Error Resume Next ' 忽略错误,后续可根据 Err.Number 判断具体错误
FileCopy sourceFile, destinationFile
If Err.Number = 0 Then
MsgBox "文件复制成功!"
Else
MsgBox "文件复制失败,错误代码: " & Err.Number & ",错误描述: " & Err.Description
End If
Err.Clear ' 清除错误信息
End Sub