View Full Version : Date in File Name


RaunLGoode
06-20-2008, 12:10 PM
I have a report generated in Excel. I would like to Save the report as "Employee Name-Date", using the following code:

ActiveWorkbook.SaveAs Filename:= _
"\\[Path]\" & CName & "-" & WEDate & ".xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

When I try th execute the code I get an error. When I remove the Date Variable (In Red) the code runs with no error. I suspect the problem lies in the date data type of the date variable. There must be a way to modify the variable so I can use it as part of the file name. Could somebody give me some help?

Alc
06-20-2008, 12:14 PM
Would this work?

ActiveWorkbook.SaveAs Filename:= _
"\\[Path]\" & CName & "-" & Str(WEDate) & ".xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

RaunLGoode
06-23-2008, 08:42 AM
Unfortunately, I get the same error. Any other suggestions
I am using Excel 2003 /Win XP

lemo
06-27-2008, 09:37 AM
maybe it doesn't like the slashes? (i am assuming you are using mm/dd/yy, or similar.) see if it will work if you play with the date format, eg use mm-dd-yy, or even better custom mmddyyyy or similar.
just an idea.
l