Save workbook to 2 different locations macro and rename one of them

Buns1976

Board Regular
Joined
Feb 11, 2019
Messages
194
Office Version
  1. 365
Platform
  1. Windows
Good Morning Everyone,

I'm trying to come up with a macro that will save a workbook in two different locations.This workbook gets used ONCE per day so for example, the original file resides on the desktop and I want to save that as the original file "C:\Users\Leasburg Front Count\Desktop\LOTTERY.XLSB" .

The 2nd part of the equation is a little stickier. I want to save that as "C:\Users\Leasburg Front Count\Dropbox\LOTTERY BACKUP\LOTTERY.XLSB"
BUT not overwrite the file from the previous save so maybe it saves as LOTTERY.XLSB(2), LOTTERY.XLSB(3), etc or what would be even better is
if we could save it as the current date so something like this LOTTERY2-25-19.XLSB OR something similar to that.

Thank you!
 
Re: How to save workbook to 2 different locations macro and rename one of them

My pleasure. :)
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Re: How to save workbook to 2 different locations macro and rename one of them

Hi Mumps,
I'm having an issue with my people closing and opening the workbook which is overwriting my backup file.
Is there a way to add the TIME of DAY to the file name for example "LOTTERY_ 02-25-19 08:59" or something similar?



Code:
[COLOR=#333333]Code:[/COLOR]
[COLOR=#333333]Sub SaveToLocations()[/COLOR]
[COLOR=#333333]ActiveWorkbook.SaveAs Filename:="C:\Users\Leasburg Front Count\Desktop\LOTTERY.XLSB"[/COLOR]
[COLOR=#333333]ActiveWorkbook.SaveAs Filename:="C:\Users\Leasburg Front Count\Dropbox\LOTTERY BACKUP\LOTTERY" & Format(Date - 1, "mm-dd-yy") & ".XLSB"[/COLOR]
[COLOR=#333333]End Sub[/COLOR]


 
Last edited:
Upvote 0
Re: How to save workbook to 2 different locations macro and rename one of them

Try:
Code:
Sub SaveToLocations()
    ActiveWorkbook.SaveAs Filename:="C:\Users\Leasburg Front Count\Desktop\LOTTERY.XLSB"
    ActiveWorkbook.SaveAs Filename:="C:\Users\Leasburg Front Count\Dropbox\LOTTERY BACKUP\LOTTERY" & Format(Now() - 1, "mm-dd-yy hh:mm AMPM") & ".XLSB"
End Sub
 
Upvote 0
Re: How to save workbook to 2 different locations macro and rename one of them

Hi Mumps,

I didn't like that code! I dropped the screenshot of the errors in the Dropbox folder you have access to!

Thanks
 
Upvote 0
Re: How to save workbook to 2 different locations macro and rename one of them

Any reason why you didn't like the code? Did it not work?
 
Upvote 0
Re: How to save workbook to 2 different locations macro and rename one of them

Hi Mumps,
Excel didn't like it! Not sure what the deal is. Were you able to see the screenshot of the errors?

Thank you!
 
Last edited:
Upvote 0
Re: How to save workbook to 2 different locations macro and rename one of them

Give this a try:
Code:
Sub SaveToLocations()
    ActiveWorkbook.SaveAs Filename:="C:\Users\Leasburg Front Count\Desktop\LOTTERY.XLSB", FileFormat:=50
    ActiveWorkbook.SaveAs Filename:="C:\Users\Leasburg Front Count\Dropbox\LOTTERY BACKUP\LOTTERY" & Format(Now() - 1, "mm-dd-yy hh.mm AMPM") & ".XLSB", FileFormat:=50
End Sub
 
Last edited:
Upvote 0
Re: How to save workbook to 2 different locations macro and rename one of them

That got it! Out of curiosity, what does "FileFormat:=50" represent?

Thanks a TON or TONNE in your speak!!
 
Upvote 0
Re: How to save workbook to 2 different locations macro and rename one of them

"FileFormat:=50" saves the file in "xlsb" format. Also, there was another problem in the way the time was formatted. The original macro used a ":" as a separator between the hour and minutes. The semicolon is reserved by Excel so you can't use it as a part of a file name. You will notice that I changed it to a period.
 
Upvote 0
Re: How to save workbook to 2 different locations macro and rename one of them

I did notice that. I tried a couple of things rather than the colon but couldn't get it to show the time!

Once again, THANK YOU SO MUCH!!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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