Saving A Workbook With A Varaiable File Name

Owen.OSullivan

New Member
Joined
Apr 5, 2011
Messages
3
Hi,

Once every day at a specific time, I am opening an excel workbook as a scheduled task and then running a macro activated with Auto_Open. I want to save the file as part of the macro but want the name to change to indicate the date that the workbook was opened and the macro activated.

For example, I want the workbook to be saved as "Daily Carriage Analysis 05-04-2011" when saved on the fifth of April 2011 and as "Daily Carriage Analysis 06-04-2011" when saved on the sixth of April 2011 etc.

I can build the file name (including the folder path) in a cell in the work book as part of the macro but just cannot use that built name to save the file.

Is this possible?

Any help, much appreciated.

Many thanks.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Owen,

Welcome to the forum,

If you hold the date in a cell or refer to it at the time of saving it is possible, but you might need to format it at the time of saving then include the file extension as well otherwise it doesn't like it. I haven't tested this but give it a go.

Code:
Sub saveMe()
ActiveWorkbook.SaveAs Range("B2").Value & Format(Date, "dd mm yyyy") & ".xls"
End Sub
 
Upvote 0
Welcome to MrExcel board....


Public Sub SaveAsA1()</PRE>
ThisFile = Range("A1").Value<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></PRE>
ActiveWorkbook.SaveAs Filename:=ThisFile<o:p></o:p></PRE>
End Sub<o:p></o:p></PRE>
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,522
Members
452,923
Latest member
JackiG

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