VBA將文件夾D:\Users\qiang_gong\Downloads下所有excel移動到\172.28.192.40\f9\客戶服務中心\維修第一本部\Zidonghua\週報\資料下載如果文件重複就覆蓋
时间: 2023-09-04 08:17:40 浏览: 40
以下是VBA代码实现:
```vb
Sub MoveExcelFiles()
Dim sourceFolder As String, destFolder As String
Dim file As String
sourceFolder = "D:\Users\qiang_gong\Downloads\"
destFolder = "\\172.28.192.40\f9\客戶服務中心\維修第一本部\Zidonghua\週報\資料下載\"
' Loop through all Excel files in source folder
file = Dir(sourceFolder & "*.xls*")
While file <> ""
' Move the file to destination folder with overwrite
FileCopy sourceFolder & file, destFolder & file
Kill sourceFolder & file
file = Dir()
Wend
MsgBox "All Excel files have been moved!"
End Sub
```
请将上述代码复制到一个新的模块中。代码中,`sourceFolder` 和 `destFolder` 分别为源文件夹和目标文件夹的路径。`file = Dir(sourceFolder & "*.xls*")` 用于找到源文件夹中所有以 `.xls` 或 `.xlsx` 结尾的 Excel 文件。然后,使用 `FileCopy` 函数将文件复制到目标文件夹,并使用 `Kill` 函数删除源文件夹中的文件。最后,弹出一个消息框,告诉用户所有 Excel 文件已经移动。