VBA 将文件从一个目录复制到另一个目录 [英] VBA to copy a file from one directory to another

查看:85
本文介绍了VBA 将文件从一个目录复制到另一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个访问文件,我经常需要将它复制到另一个目录,替换上一个版本.我想使用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:DatabaseoldName.accdb"
   copyDestination = "Y:dbstore"
   newName = "newName.accdb"

有没有简单的方法可以做到这一点?

Is there an easy way of doing this?

推荐答案

在 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] )

其中源和目标是文件的全名(包括路径).

where source and destination are the full names (including paths) of the file.

请参阅 https:///docs.microsoft.com/en-us/office/vba/Language/Reference/user-interface-help/copyfile-method

这篇关于VBA 将文件从一个目录复制到另一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆