Using Date in Filename

  • Thread starter Thread starter Phil Amey
  • Start date Start date
P

Phil Amey

Can anyone tell me how I can use a date in a filename in an Excel Macro

I keep getting a problem with the "/" in the date and cannot see how to get around it.

Your help would be appreciated.

Philip Amey
 
Phil Amey said:
Can anyone tell me how I can use a date in a filename in an Excel Macro

I keep getting a problem with the "/" in the date and cannot see how to get around it.

Your help would be appreciated.

Philip Amey

Try a different way of expressing the date that doesn't involve the "/"
character, for example 16-9-03 or 16Sep03.
 
One way:

fName = "filename_" & Format(Date, "dd-mmm-yyyy") & ".xls"
ThisWorkbook.SaveAs fName
 
As you've pointed out, in Windows, you cannot have a "/" in a file name.
Here's an alternative:

ThisWorkbook.SaveAs (Format(Date, "YYYY-MM-DD"))

--
HTH -

-Frank
Microsoft Excel MVP
Dolphin Technology Corp.
http://vbapro.com
 
I would certainly make that yyyy-mm-dd so that it can be
sorted as you would normally see names in a directory
and select a file in the most logical order..

yyyy-mm-dd (with hyphens and 4 digit year) is the ISO standard.
 
Back
Top