通过访问 vba 复制和粘贴文件 [英] Copy and paste a file through access vba
本文介绍了通过访问 vba 复制和粘贴文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要检查一个文件夹中的文件,如果它存在就删除它并用更新的版本替换它,或者如果文件没有删除,那么它会将文件从路径复制到个人驱动器中
I need to check a folder for a file, if it exists delete it an replace it with an updated version, or if the file doesn't delete then it will copy the file from a path into the individuals personal drive
我的代码:
Dim FileExistsbol As Boolean
Dim stFileName As String
Dim CopyFrom As String
Dim CopyTo As String
stFileName = "H:\Test File.txt"
stFileName = Trim(stFileName)
FileExistsbol = dir(stFileName) <> vbNullString
If FileExistsbol Then
Kill stFileName
CopyFrom = "J:\Test File.txt"
CopyTo = "H:\"
FileSystemObject.CopyFile CopyFrom, CopyTo
Else
CopyFrom = "J:\Test File.txt"
CopyTo = "H:\"
FileSystemObject.CopyFile CopyFrom, CopyTo
End If
发生了什么:
代码按预期执行并删除现有文件,但在复制和粘贴部分似乎失败.
The code executes and deletes the existing file as expected, but it appears to be failing on the copy and paste part.
错误:
出现的调试是:
需要对象
推荐答案
裸骨:
Dim fso As Object 'filesystemobject
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile strSourcePathWithFileAndExt, strDestPathWithFinalBackslash
Set fso = Nothing
这篇关于通过访问 vba 复制和粘贴文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文