Move ALL files (or of a specific file type) from one folder into another folder

Vikas Verma's picture

Sub MoveFilesFolder2Folder()
Dim fso
Dim sfol As String, dfol As String

sfol = "c:\MyFolder" ' change to match the source folder path
dfol = "e:\MyFolder" ' change to match the destination folder path

Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next

If Not fso.FolderExists(sfol) Then
MsgBox sfol & " is not a valid folder/path.", vbInformation, "Invalid Source"
ElseIf Not fso.FolderExists(dfol) Then
MsgBox dfol & " is not a valid folder/path.", vbInformation, "Invalid Destination"
Else
fso.MoveFile (sfol & "\*.*"), dfol ' Change "\*.*" to "\*.xls" to move Excel Files only
End If
If Err.Number = 53 Then MsgBox "File not found"

End Sub