|
Sub 移动文件()
Dim OldName As String
Dim NewName As String
OldName = ThisWorkbook.Path & "\VBA其实很简单.xlsm" '原文件名
NewName = ThisWorkbook.Path & "\目标目录\VBA其实很简单.xlsm" '新文件名
Name OldName As NewName '不更改文件名,但将其移动到另外一个文件夹
MsgBox "文件已经被移动了"
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
If fso.FileExists(myFile) Then
fso.MoveFile myFile, myNewFilePath
MsgBox "已经将文件 " & myFile & " 移到了文件夹 " & myNewFilePath
Else
MsgBox "要移动的文件不存在"
End If
Set fso = Nothing
End Sub |
|