|
复制文件同样也可以有多种思路和方法选择,比如:
Sub 复制文件()
Dim mySource As String, myDes As String
On Error GoTo ErrorHandler
mySource = ThisWorkbook.Path & "\VBA其实很简单.xlsm"
myDes = ThisWorkbook.Path & "\目标目录\VBA其实很简单.xlsm"
FileCopy mySource, myDes
MsgBox "复制成功!"
Exit Sub
ErrorHandler:
If Err.Number <> 0 Then
MsgBox "无法复制该文件!" & vbCrLf & Err.Description
End If
End Sub
Sub 复制文件()
Dim myFile As String
Dim myNewFilePath As String
Dim fso As Scripting.FileSystemObject
myFile = ThisWorkbook.Path & "\VBA其实很简单.xlsm" '要复制的文件
myNewFilePath = ThisWorkbook.Path & "\目标目录\" '要复制到的目标位置
Set fso = New Scripting.FileSystemObject
fso.CopyFile myFile, myNewFilePath, overwritefiles:=True
MsgBox "已经将文件 " & myFile & " 复制到文件夹 " & myNewFilePath
Set fso = Nothing
End Sub |
|