![](/img/trans.png)
[英]How to copy a cell value from one excel file and paste it to another excel file?
[英]Excel - copy file from one folder to another if cell is clicked on
当用户单击excel中的单元格时,我试图将文件从一个文件夹复制到另一个文件夹。
我不断收到一条错误消息,指出“找不到文件”错误,我也不知道为什么。
我的文件夹名称中包含空格,所以我不知道这是否可能是问题的原因,我尝试删除文件夹路径中的空格,但是发生相同的错误。 有人可以先告诉我怎么办吗谢谢
If Target.Column = Range("C1").Column Then
If Target.Row > 9 Then
'Declare Variables
Dim FSO
Dim sFile As String
Dim sSFolder As String
Dim sDFolder As String
'This is Your File Name which you want to Copy
sFile = "Supplier Audit.xls"
'Change to match the source folder path
sSFolder = "\\UKSH000-FILE06\purchasing\New Supplier Set-Ups\assets"
'Change to match the destination folder path
sDFolder = "\\UKSH000-FILE06\purchasing\New Supplier Set-Ups\AX ATTACHMENTS\TEST"
'Create Object
Set FSO = CreateObject("Scripting.FileSystemObject")
'Checking If File Is Located in the Source Folder
If Not FSO.FileExists(sSFolder & sFile) Then
MsgBox "Specified File Not Found", vbInformation, "Not Found"
'Copying If the Same File is Not Located in the Destination Folder
ElseIf Not FSO.FileExists(sDFolder & sFile) Then
FSO.CopyFile (sSFolder & sFile), sDFolder, True
MsgBox "Specified File Copied Successfully", vbInformation, "Done!"
Else
MsgBox "Specified File Already Exists In The Destination Folder", vbExclamation, "File Already Exists"
End If
End If
End If
您已经错过了sSFolder
末尾的sSFolder
。 这就是为什么sDFolder & sFile
结果为
\\UKSH000-FILE06\purchasing\New Supplier Set-Ups\assetsSupplier Audit.xls.
在sDFolder
的末尾也sDFolder
一个反斜杠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.