VBA将文件从一个目录复制到另一个目录 [英] VBA to copy a file from one directory to another
问题描述
所以我有一个访问文件,我经常需要复制到另一个目录,替换最后的版本。
我想使用一个Excel宏来实现这一点,并且还希望在过程中重命名该文件。
So I have an access file that I regularly need copied to another directory, replacing the last version. I would like to use an Excel macro to achieve this, and would also like to rename the file in the process.
例如
fileName = "X:\Database\oldName.accdb"
copyDestination = "Y:\dbstore\"
newName = "newName.accdb"
有一个简单的方法吗?
推荐答案
在Scripting.FileSystemObject中使用适当的方法。然后你的代码将更容易移植到VBScript和VB.net。为了让您开始,您需要包含:
Use the appropriate methods in Scripting.FileSystemObject. Then your code will be more portable to VBScript and VB.net. To get you started, you'll need to include:
Dim fso As Object
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
然后您可以使用
Call fso.CopyFile(source, destination[, overwrite] )
b $ b
其中source和destination是文件的全名(包括路径)。
where source and destination are the full names (including paths) of the file.
请参阅 http://msdn.microsoft.com/en-us/library/aa711216(v = vs.71).aspx
这篇关于VBA将文件从一个目录复制到另一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!