excel vba - 将文件从一个文件夹复制到另一个文件夹,但如果文件存在不覆盖?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26033696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
excel vba - copy file from one folder to another but if file exists do not overwrite?
提问by james tanner
Can someone please show me a way of copying a file from one folder to another using vba but with a condition to say if file already exists do not overwrite?
有人可以告诉我一种使用 vba 将文件从一个文件夹复制到另一个文件夹的方法,但有条件说明文件是否已经存在不要覆盖吗?
here is my code:
这是我的代码:
If Target.Column = Range("BL1").Column And Target.Row > 14 Then
FileCopy "\UKSH000-FILE06\purchasing\New_Supplier_Set_Ups_&_Audits\assets\audit.xls", "\UKSH000-FILE06\purchasing\New_Supplier_Set_Ups_&_Audits\ATTACHMENTS\" & Range("B" & ActiveCell.Row) & "\audit.xls"
End If
回答by nekomatic
Simplifying your paths a bit for clarity:
为清楚起见,稍微简化您的路径:
Set fs = CreateObject("Scripting.FileSystemObject")
If Not fs.FileExists("\path\to\destination" & stuff & "\audit.xls") Then
FileCopy "\path\to\source\audit.xls", "\path\to\destination\" & stuff & "\audit.xls"
End If
回答by Kunal
FileCopy (sourceString, DestinationString, Boolean) Set Boolean to TRUE if destination can be overwritten, by default it is false.
FileCopy (sourceString, DestinationString, Boolean) 如果目标可以被覆盖,则将 Boolean 设置为 TRUE,默认情况下为 false。