我想用 excel VBA 更新当前子文件夹中的文件。第一步是在子文件夹中查找文件名。把它们都列在另一张纸上,这样我就可以记录下来。复制并用新文件覆盖文件,因此我的所有文件夹和子文件夹都将使用新文件进行更新。
source
D:\home
destination
D:\dest\cus1\...
我目前正在使用下面的代码,但我至少需要改进 for 循环或任何新算法。你能帮忙吗?
Sub sbCopyingAllExcelFiles()
Dim FSO
Dim sFolder As String
Dim dFolder As String
sFolder = "c:\Users\osmanerc\Desktop\STATUS\" ' change to match the source folder path
dFolder = "\\manfile\ELEKTRONIK\MUSTERI DESTEK\ECN management\" ' change to match the destination folder path
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FolderExists(sFolder) Then
MsgBox "Source Folder Not Found", vbInformation, "Source Not Found!"
ElseIf Not FSO.FolderExists(dFolder) Then
MsgBox "Destination Folder Not Found", vbInformation, "Destination Not Found!"
Else
FSO.CopyFile (sFolder & "\*.xl*"), dFolder
MsgBox "Successfully Copied All Excel Files to Destination", vbInformation, "Done!"
End If
End Sub