I would like to update a file in current subfolders with excel VBA. First step is looking for a file name in subfolders. List them all in another sheet so I can keep log for that. Copy and overwrite the file with new file, so all my folders and subfolders will be updated with new file.
source
D:\home
destination
D:\dest\cus1\...
I am currently using below code, but I need to improve at least for loop or any new algorithm. Can you please help?
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
So this should be able to copy all of the files from your source that match the
Like sFolder & "\*.xl*"pattern. You can add more calls if you have more folders to work with.