Save date in filename

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi. I would like to have the current date saved in the
filename when the macro is excercised.

For instance, the filename is "Log File.xls". I would
like a command that, if executed on February 23, it would
save the filename "Log File - 2/23/04.xls.

My current command is:

ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path
& "\Archive\" & "Log File"

What should I add to this command to include the date?

Thanks,
Mike.
 
Rob:

Thanks for your reply. When I try this, I get a run time
error. It says it cannot access the file ....
\Archive\Log File-2\23.

It appears as if it is treating the slashes in the date
as directory paths ... Any ideas?

Thanks,
Mike.
 
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path
& "\Archive\" & "Log File " & format(date,"mmddyy") & ".xls"

Or one of the combinations below to start.

format(date,"mmm dd yyyy")
format(date,"mm dd yy")
format(date,"mm dd yyyy")

When I append dates, I don't fool around with backslashes or slashes.

HTH
Paul
 
Oops, it's past my bedtime!

Paul is correct, and my only excuse is that my date separator is set up
as a dash, so out of habit I ignored the slash in your example.

Sorry for the confusion.
 
(e-mail address removed) postulated on 2/24/2004 12:34 AM:
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path
& "\Archive\" & "Log File " & format(date,"mmddyy") & ".xls"

Or one of the combinations below to start.

format(date,"mmm dd yyyy")
format(date,"mm dd yy")
format(date,"mm dd yyyy")

When I append dates, I don't fool around with backslashes or slashes.

HTH
Paul

If sorting the files in chronological order is important, you may want
to consider formatting year first, then month, and finally day.
format(date,"yymmdd")


"Every little BYTE helps"
 
Back
Top