VBA Code to save workbook as "filename" and current date

chrissmarlow

Board Regular
Joined
Jun 3, 2010
Messages
59
Hi guys,

I am looking for code to add to the end of my macro which will save the file as "SRS Sheet - " and then the current date. I want it to save in a folder within the path the current workbook is located, ie. T:\Macrosheet is where the file is now, I want it to save to T:\Macrosheet\Reports

Can anyone help me out with this?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try like this

Code:
ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "\Reports\SRS Sheet - " & Format(Date, ddmmyyyy) & ".xls"
 
Upvote 0
I would try something like:



Code:
NewPath = Mid(ThisWorkbook.FullName, 1, Len(ThisWorkbook.FullName) - Len(ThisWorkbook.Name)) & "\Reports\" & "SRS Sheet - " & Format(Date, "dd-mm-yyyy") & ".xlsx"

ThisWorkbook.SaveAs(NewPath)
Please note that ".xlsx" is just for Excel 2007+, so change that according to your needs. Any questions plz ask :)
 
Upvote 0
I would try something like:



Code:
NewPath = Mid(ThisWorkbook.FullName, 1, Len(ThisWorkbook.FullName) - Len(ThisWorkbook.Name)) & "\Reports\" & "SRS Sheet - " & Format(Date, "dd-mm-yyyy") & ".xlsx"
 
ThisWorkbook.SaveAs(NewPath)
Please note that ".xlsx" is just for Excel 2007+, so change that according to your needs. Any questions plz ask :)

Try like this

Code:
ActiveWorkbook.SaveAs Filename:=ActiveWorkbook.Path & "\Reports\SRS Sheet - " & Format(Date, ddmmyyyy) & ".xls"

Thanks for your help
 
Upvote 0
Hi,

If I want to save it in the same folder as the current one?
Can you suggest me the changes to this code?

Thx



I would try something like:



Code:
NewPath = Mid(ThisWorkbook.FullName, 1, Len(ThisWorkbook.FullName) - Len(ThisWorkbook.Name)) & "\Reports\" & "SRS Sheet - " & Format(Date, "dd-mm-yyyy") & ".xlsx"

ThisWorkbook.SaveAs(NewPath)
Please note that ".xlsx" is just for Excel 2007+, so change that according to your needs. Any questions plz ask :)
 
Upvote 0
Thx Blade for your quick reply.
I used the below code in a command button. But nothing happened and no errors either.


NewPath = Mid(ThisWorkbook.FullName, 1, _
Len(ThisWorkbook.FullName) - Len(ThisWorkbook.Name)) & "\" & "SRS Sheet - " & Format(Date, "dd-mm-yyyy") & ".xlsm"
 
Upvote 0
This is not exactly what you have asked for but it can be pretty easily modified for your purposes.

I like to make backups of my workbooks. So I usually create a folder in the same folder as the workbook called Backups. When I run this macro that is where my file is saved.

Code:
[COLOR=#000000][FONT=Courier New]Sub BackupMyWorkbook()[/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New]ThisWorkbook.SaveCopyAs _[/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New]Filename:=ThisWorkbook.Path & "\Backups\" & _[/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New]Format(Now(), "yyyy-mm-dd hh mm AMPM") & " " & _[/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New]ThisWorkbook.Name[/FONT][/COLOR]
[COLOR=#000000][FONT=Courier New]End Sub[/FONT][/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

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