VBA使用FileSystemObject複製或移動文件
- 2017-08-08 16:50:00
- zstmtony 原創
- 7931
以下VBA代碼 使用FileSystemObject複製或移動文件,適用於access excel等VBA環境
Public Sub Move_File() Dim strSource As Variant Dim strDestination As String Dim objFS As Object strSource = "C:\Temp_C\Test.txt" '源路徑 strDestination = "C:\Temp_Test\Test.txt" '目標路徑 Set objFS = CreateObject("Scripting.FileSystemObject") '創建FileSystemObject fso對象 With objFS If .FileExists(strDestination) Then .DeleteFile (strDestination) ‘如果目標文件存在,先刪除目標文件 End If .MoveFile strSource, strDestination '移動文件 End With Set objFS = Nothing End Sub
文章分類
聯繫我們
聯繫人: | 王先生 |
---|---|
Email: | 18449932@qq.com |
QQ: | 18449932 |
微博: | officecn01 |