简体   繁体   English

Excel宏会覆盖现有文件

[英]Excel macro overwrite existing file

I am trying to move many Excel files using a wildcard from \\Output folder to \\Output\\Archive folder. 我正在尝试使用通配符将许多Excel文件从\\Output文件夹移至\\Output\\Archive文件夹。 If a file is already present in the Archive folder, it should be overwritten. 如果存档文件夹中已经存在文件,则应将其覆盖。

打印我的代码的屏幕

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. TIA,Sanket K.

This is a duplicate . 这是重复的 You cannot use MoveFile if the destination file already exists. 如果目标文件已存在,则不能使用MoveFile。 Best to use CopyFile and DeleteFile 最好使用CopyFile和DeleteFile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM