Saturday, April 20, 2019

Copy all Excel Files One Folder to Another in VBA Excel

Copy all Excel Files One Folder to Another in VBA Excel


'In this Example I am Coping all excel files from one Folder ("C:\Temp\") to another Folder ("D:\Job\")
Sub sbCopyingAllExcelFiles()

Dim FSO
Dim sFolder As String
Dim dFolder As String

sFolder = "C:\Temp\" ' change to match the source folder path
dFolder = "D:\Job\" ' 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

No comments:

Post a Comment