Hello,
I'm using this code to move all my Excel files from 1 folder to another. The code is working file. I need your help to edit the code to overwrite the files in the destination folder if the file names in the source & destination folders are the same. I've tried Application.DisplayAlerts = False but it does not work. Thanks for your help.
I'm using this code to move all my Excel files from 1 folder to another. The code is working file. I need your help to edit the code to overwrite the files in the destination folder if the file names in the source & destination folders are the same. I've tried Application.DisplayAlerts = False but it does not work. Thanks for your help.
Code:
Sub test1()
Application.DisplayAlerts = False
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FileExt As String
Dim FNames As String
FromPath = "E:\path3"
ToPath = "E:\path5\"
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.MoveFile Source:=FromPath & FileExt, Destination:=ToPath
End Sub