Today's date as file name .csv in Xl 2007

L

LuisE

What is the code to save a file as a csv which name is today's date? I'm
using Excel 2007.

Thanks in advance
 
R

Rick Rothstein

You didn't say what format you would want the date in (remembering, of
course, that you can't use slashes in a file name) nor whether you were
trying to save a single worksheet or the entire workbook. Assuming you
wanted to only save a single worksheet, you could use this code line to do
what you asked (note that the $ sign on the Date function call is required;
also, change the directory path from my example "d:\temp" to wherever you
actually want to save it at)....

Worksheets("Sheet1").SaveAs "d:\temp\" & Date$ & ".csv", xlCSV

Or you can make your own date format string using the Format function,
something like this...

Worksheets("Sheet1").SaveAs "d:\temp\" & Format(Date, _
"ddmmmyyyy") & ".csv", xlCSV

You may want to look up the SaveAs method in the help files as there are
additional options available.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top