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.
 

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Trevor G

Well-known Member
Joined
Jul 17, 2008
Messages
6,672
Office Version
  1. 2016
Platform
  1. Windows
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
 

texasalynn

Well-known Member
Joined
May 19, 2002
Messages
8,458
Welcome to MrExcel board....


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

Watch MrExcel Video

Forum statistics

Threads
1,108,985
Messages
5,526,063
Members
409,685
Latest member
Davetom

This Week's Hot Topics

Top