PDA

View Full Version : Adding Date to File name



nkechifesie
07-04-2007, 02:20 AM
Hi, I have written a VBA program that runs on Excel and puts data on the excel sheet. This runs everyday. I want to be adding the dates to the files, this date is gotten from the excel sheet that uploads into the report excel file. Below is the Code I wrote which doesnt work, please could you help me



Sheets("Matrix sheet").Select
Today = Cells(1, 1) 'The location of the date on the raw sheet
Today = Format(Today, "dd-mm-yyyy")
Windows("cells.xls").Close savechanges:=True, Filename:="c:\Daily_Alerts\Daily Alerts_ " & Today & " "

Bob Phillips
07-04-2007, 02:27 AM
ActiveWorkbook.Close savechanges:=True, Filename:="c:\Daily_Alerts\Daily Alerts_ " & Today

RichardSchollar
07-04-2007, 02:31 AM
Hi

Perhaps:

Today = Format(Sheets("Matrix sheet").Range("A1").Value,"dd-mm-yyyy")
ActiveWorkbook.SaveAs Filename:="c:\Daily_Alerts\Daily Alerts_ " & Today & ".xls"
ActiveWorkbook.Close SaveChanges:=False

Richard

mdmackillop
07-04-2007, 01:37 PM
When it comes to file names, it may be more useful to store the date in reverse order; you can then arrange in ascending/descending order
e.g.
Today = Format(Sheets("Matrix sheet").Range("A1").Value,"yyyy-mm-dd")

nkechifesie
07-06-2007, 03:45 AM
I have resolved it. The issue was that .xls was not included in the file name. Thanks for all your help.
Below is the code that works now



Dim Today As Date
Dim Todayb As String
Today = Cells(1, 1)
Todayb = Format(Today, "dd-mm-yyyy")
Todayb = Todayb & ".xls"
Windows("cells.xls").Close savechanges:=True, Filename:="c:\Daily_Alerts\Daily Alerts_" & Todayb & " "

paulked
07-06-2007, 04:10 AM
When it comes to file names, it may be more useful to store the date in reverse order; you can then arrange in ascending/descending order :clever:

nkechifesie,

I'd take this format on board, It will make locating files a lot easier.

Paul Ked

nkechifesie
07-06-2007, 04:23 AM
No problem, would like to be of help to others, meanwhile could you please explain your quote.

Bob Phillips
07-06-2007, 04:27 AM
If you used Workbooks not windows, I don't think you would have had a problem.

mdmackillop
07-06-2007, 05:44 AM
No problem, would like to be of help to others, meanwhile could you please explain your quote.
See Post 4
If you format the date as dd-mm-yy, when you sort in Explorer, it will arrange by day/month/year ie the first of all months come first. Format as yyyy-mm-dd, and you can sort files in date order.

Bob Phillips
07-06-2007, 05:51 AM
No problem, would like to be of help to others, meanwhile could you please explain your quote.

Always in the s#*t, only the depth varies

Simon Lloyd
07-06-2007, 11:33 AM
Nice quote Bob, but doesn't the viscosity enter in to the equation?, sometimes it's not so deep but takes a hell of a lot of wading through!

Bob Phillips
07-06-2007, 11:47 AM
We don't have that distinction dan sowff!