vba code to copy and paste the current workbook

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I need some vba code that will make a copy of the current workbook. Can someone help me please?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Copies the file to C:\Temp as copybook.xls

Code:
Sub MM1()
ActiveWorkbook.SaveCopyAs Filename:="C:\Temp\CopyBook.xls"
End Sub
 
Upvote 0
If I exclude the path, does it save to the same directory as the original file?
 
Upvote 0
Yes...

Code:
ActiveWorkbook.SaveAs "CopyBook.xls"
 
Upvote 0
Thanks Michael. I have sheets that go from July 2018 to June 2019. The file name for instance is 2018-2019.xlsm. After June 2019 has gone and a new document needed, I want a button that will make a copy of the spreadsheet with the new name of the document for the new financial year. Do you have any ideas how I might go about doing that?
 
Upvote 0
Untested

Code:
Sub MM1()
ActiveWorkbook.SaveAs Format(Date, "yyyy") & "-" & Format(Date, "yyyy") + 1 & ".xlsx"
End Sub
 
Upvote 0
Update...
will save as a macro enabled workbook, so the code goes with it.

Code:
Sub MM1()
ActiveWorkbook.SaveAs Format(Date, "yyyy") & " - " & Format(Date, "yyyy") + 1 & ".xlsm", FileFormat:=52
End Sub
 
Upvote 0
Thanks, that's good but I wanted a new workbook to open and have everything pasted into it so you have a separate file.
 
Upvote 0
you mean you wanted all the new months created once the workbook is saved ??
so June 2018 would become june 2019 ??
 
Upvote 0
Eventually I will want that but I was talking about for now, I just want to press a button and for a new document to appear and for it to be an exact copy of the already open document. The filename of the new document needs to be set to June- July of the next financial year.

I will also want the sheet names to be updated accordingly, but I think I know how to do that one, but I guess, if you could also add it in here incase I can't work it out.

Thanks Michael.
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,572
Members
448,972
Latest member
Shantanu2024

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