excel - 如何使用 VBA 将文件从一个目录复制到另一个目录
问题描述
我希望能够将 excel 文件从一个文件夹复制到另一个文件夹。但是,每次复制它时,我都想将名称更改为 TABLEAUPCQ1、TABLEAUPCQ2、TABLEAUPCQ3 等等。
原因是,如果有人已经在其他路径中使用它,我无法覆盖 excel 文件。
Sub CopierFichier()
Dim fso As Object
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
Call fso.CopyFile("R:\ASP\PCQ_BEHESP\SuiviPCQAssignations\TABLEAUPCQ.xlsm", "V:\DGI\11000_Surveillance\11200_InstallationsSousPression\PCQ\Suivi\TABLEAUPCQ.xlsm")
End Sub
解决方案
在单元格值内的每个子执行后,计数器加 1。这样,您就可以将当前计数存储在函数之外。
抓住它,使用它,增加它。
Sub CopierFichier()
Dim counter_var As String
Dim fso As Object
Set fso = VBA.CreateObject("Scripting.FileSystemObject")
counter_var = Cells(1, 1).Value
Call fso.CopyFile("R:\ASP\PCQ_BEHESP\SuiviPCQAssignations\TABLEAUPCQ.xlsm", "V:\DGI\11000_Surveillance\11200_InstallationsSousPression\PCQ\Suivi\TABLEAUPCQ_COPIE_" + counter_var + ".xlsm")
Cells(1, 1).Value = Cells(1, 1).Value + 1
End Sub
我纠正了这个小错误。
推荐阅读
- r - 如果我的数据不是时间序列而只是大量文本行,则使用什么来代替“滞后”
- java - 插入期间的 jpa 映射问题(父/子) - 无法将 NULL 插入
- javascript - LeafletJS:是否可以在 VectorLayer 上显示 ImageOverlay?
- azure - 带或不带 docker 的 Azure 应用服务
- corda - 在 Corda 中,如何使用 `CompositeKey` 作为必需的签名者?
- python - 如何在python中使用变量访问网页
- openshift - 在 Redhat Openshift 中获取 Assemble 脚本失败错误构建应用程序
- asp.net-core-mvc - 将 .Net Core Identity 与通用存储库一起使用
- mysql - galera_new_cluster:找不到命令
- javascript - 我可以在不触发 404 警告的情况下使用 JS 检查文件是否存在吗?