简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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