save same document to 2 different folders

rjmdc

Well-known Member
Joined
Apr 29, 2020
Messages
672
Office Version
  1. 365
Platform
  1. Windows
hi
this is the part of code i am stuck at i think i made amistake trying to save at once into 2 folders


Rich (BB code):
With ActiveWorkbook.Worksheets("IDGS Billing")
        FileName = "IDGS" & " " & Format(DateFrom, "m.d.yyyy") & " - " & Format(DateTo, "m.d.yyyy") & " " & MissingDiagnosisIDGS & " - " & NextID & " - " & IDGSTotal
        Set tbl = .ListObjects(1)
        tbl.Range.Copy
    End With
    
    Set wb = Workbooks.Add
    wb.Activate
    wb.Sheets(1).Range("A1").PasteSpecial xlPasteAll
    'wb.Sheets(1).Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
    ActiveWorkbook.Queries("IDGS Billing").Delete
    Selection.Columns.AutoFit
             
    FullFileName = FileName & " " & "(" & FileDateTime & ")" & ".xlsx"
    
    'Save and Close New WB
    wb.SaveAs SaveFolder & "\" & FullFileName, xlOpenXMLWorkbook
    wb.Close SaveChanges:=False
    DoEvents
    
    wb.SaveAs SaveFolder2 & "\" & FullFileName, xlOpenXMLWorkbook this part fails what do i do to save in 2 locations?
    wb.Close SaveChanges:=False
    DoEvents
    
    'Back to Main WB
    ThisWorkbook.Activate
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi rjmdc,

if you want to save the workbook you assigned to wb at two places you should leave it open after the first save in order for it to be available for the second part of saving as well:

VBA Code:
    'Save and Close New WB
    wb.SaveAs SaveFolder & "\" & FullFileName, xlOpenXMLWorkbook
'    wb.Close SaveChanges:=False 'if you want to save the WB at a different location do not close it bere
    DoEvents
Ciao,
Holger
 
Upvote 0
i figured out that i need to copy paste save then go back to workbook copy paste and save again
 
Upvote 0
Hi rjmdc,

you get me confused as that is what happens in your code prior to saving. From what I understand you have a table you copy, add a new workbook, paste in the contents and save the new workbook with an identical name at two different locations. If there should be a change please describe like before the second saving copy over the table from a different sheet. But I would prefer to wrap that in a loop and add a workbook for each action.

Please give more precise information.

Ciao,
Holger
 
Upvote 0
my issue was i tried to copy once and save into 2 different folders
that failed
i needed to copy paste save close new book, copy paste and save again into second book

is there a way to copy 1 time and then say :
savefolder1: "M....
Savefolder2: "M....
 
Upvote 0
Hi rjmdc,

did you try to keep wb open for the second SaveAs? It works fine for me. Or could you tell if there is an error raised for the second part (what number/description)? As you have only supplied part of the code the failure might be in variable SaveFolder2. Maybe the length of FullName for the wb for SaveFolder2 is too long.

Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,215,431
Messages
6,124,855
Members
449,194
Latest member
HellScout

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top