我有一個在Excel中有50個文件路徑的列表。如何在網絡中搜索所有這些文件並將它們本地複製到我的文件夾? 如果路徑不存在於網絡中,我可以跳過這些嗎? 謝謝。VBA,使用文件路徑在本地複製和粘貼
EDIT ~~~
Sub Copy_Certain_Files_In_Folder()
'This example copy all Excel files from FromPath to ToPath.
'Note: If the files in ToPath already exist it will overwrite
'existing files in this folder
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
FromPath = "I use network file here" '<< Change
ToPath = "local here" '<< Change
FileExt = "*.csv*" '<< Change
'You can use *.* for all files or *.doc for Word files
If Right(FromPath, 1) <> "\" Then
FromPath = FromPath & "\"
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
If FSO.FolderExists(ToPath) = False Then
MsgBox ToPath & " doesn't exist"
Exit Sub
End If
FSO.CopyFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "You can find the files from " & FromPath & " in " & ToPath
End Sub
這對SO有多個答案。我首選的方法是使用scripting.filesystemobject的fileexist和其他函數查看這些關鍵字是否幫助您找到要查找的內容。 –
@科迪G。感謝代碼-y! – Jonathan
只供參考http://www.rondebruin.nl/win/s3/win026.htm –