简体   繁体   English

将工作簿保存在两个不同的驱动器位置

[英]Saving a workbook in two different drive locations

I have code which saves a document to a different saving location with a different file name. 我有将文档保存到具有不同文件名的其他保存位置的代码。

I have now been asked to save this in an additional save location (so two separate save locations) but I cannot amend the code to do so. 现在,我被要求将其保存在其他保存位置(因此有两个单独的保存位置),但是我无法修改代码来这样做。

I have tried duplicating the code which obviously didn't work, and adding in both save locations, but the doc was saved in the latter location rather than both. 我尝试过复制显然不起作用的代码,并在两个保存位置中都添加了文件,但是文档被保存在了后者而不是两个位置。 I still need the code which saves it as a certain naming convention. 我仍然需要将其另存为特定命名约定的代码。

Thanks in advance! 提前致谢!

'save workbook with different naming convention
Dim dt, wbSource, wbNam, wbDest As String
wbSource = ActiveWorkbook.FullName
wbNam = "Plan_"
dt = Format((Now), "yyyy_mm_dd  hmmAM/PM")
wbDest = ActiveWorkbook.Path & "C:\workbook location" & wbNam & dt & ".xlsm"

ActiveWorkbook.SaveAs Filename:=wbDest
Workbooks.Open Filename:=wbSource
ActiveWindow.ActivateNext

You could use something like the following 您可以使用以下内容

Dim dt As String, wbNam As String, wbDest1 As String, wbDest2 As String
Dim j As Long

wbNam = "Plan_"
dt = Format(Now, "yyyy_mm_dd hmmAM/PM")
wbDest1 = ActiveWorkbook.Path
wbDest2 = "Your second location" 

For j = 1 To 2
    ThisWorkbook.SaveCopyAs Choose(j, wbDest1, wbDest2) & "\" & wbNam & dt & ".xlsm"
Next j

This will save a copy of your workbook to two locations 这会将您的工作簿副本保存到两个位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM