Hello mvinay,
Give it a try to the attached file. I've used the following code to make it work. Here, vFrom and vTo are the range names that I've given them. The code would not only move Excel based files but also the csv files that are also frequently used in excel. Could remove it from the array if you don't want. That means, if you want you can also add the extensions which you'd like to move along with Excel files.
Let me know for if things don't work out for you.
Sub Move_XL_Files()
Dim sourcePath As String
Dim extn, fil
Dim filCount As Long
If Range("vFrom").Value <> "" And Range("vTo").Value <> "" Then
If Range("vFrom").Value <> Range("vTo").Value Then
' Checks for path entries
If Right(Range("vFrom").Value, 1) = "\" Then
sourcePath = Left(Range("vFrom").Value, Len(Range("vFrom").Value) - 1)
Else
sourcePath = Range("vFrom").Value
End If
' XL files can be in either csv, xls, xlsx, xlsm, xlsb, etc..
extn = Array("*.xl*", "*.csv")
filCount = 0
For Each ext In extn
fil = Dir(sourcePath & "\" & ext)
Do While fil <> ""
'MsgBox sourcePath & "\" & fil
FileCopy sourcePath & "\" & fil, Range("vTo").Value & "\" & fil
Kill sourcePath & "\" & fil
fil = Dir(sourcePath & "\" & ext)
filCount = filCount + 1
Loop
Next ext
MsgBox "Files successfully moved!", vbInformation, "Success!"
Else
MsgBox "Same Path. Files Not Moved"
End If
Else
MsgBox "Path field empty", vbExclamation, "Empty Path"
End If
End Sub
Bookmarks