I'm trying to move ALL excel files from one folder path to another and I'm getting a permission denied error. Here's my code:
Sub Move_Certain_Files_To_New_Folder()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String
FromPath = "R:\FromPath\Files" '<< Change
ToPath = "R:\ToPath\Backup" & Format(Now, "yyyy-mm-dd h-mm-ss")
FileExt = "*.xl*"
If Right(FromPath, 1) <> "\" Then
FromPath = FromPath & "\"
End If
FNames = Dir(FromPath & FileExt)
If Len(FNames) = 0 Then
MsgBox "No files in " & FromPath
Exit Sub
End If
Set FSO = CreateObject("scripting.filesystemobject")
FSO.CreateFolder (ToPath)
FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
MsgBox "You can find the files from " & FromPath & " in " & ToPath
End Sub
The error is from this part: FSO.MoveFile Source:=FromPath & FileExt, Destination:=ToPath Appreciate any help! :)