0

I am trying to move many Excel files using a wildcard from \Output folder to \Output\Archive folder. If a file is already present in the Archive folder, it should be overwritten.

Print screen of my code

This is my code (also shown in the attached image)

Application.DisplayAlerts = False

Dim FSO As Object
Set FSO = CreateObject("scripting.filesystemobject")

FSO.MoveFile Source:=Excel_Path & Excel_Name, Destination:=Excel_Path & "Archive\" & Excel_Name

Application.DisplayAlerts = True

It is still throwing an error

File already exists

Almost everyone suggests to disable the display alert but in my case it is not working.

Am I missing anything here? Can someone help?
TIA, Sanket K.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Sanket
  • 119
  • 1
  • 6
  • 15
  • Why not put a kill request in before the move to delete the existing file if it exists before copying the new one (note, be VERY careful and double check your DIR's before running, you don't want to kill you master files). – Dan Donoghue Jun 22 '17 at 03:24
  • `ThisWorkbook.Saved = True` or the name of the WorkBook instead of ThisWorkbook may help you. ? – Mertinc Jun 22 '17 at 03:32

1 Answers1

1

This is a duplicate. You cannot use MoveFile if the destination file already exists. Best to use CopyFile and DeleteFile

Dan
  • 231
  • 1
  • 12