English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

In an Excel Macro, I want to save a file as a report and append the filename with the current date.
Right now the code below stores the file as
Pipeline Report.xls
I would like it to be stored as:
Pipeline Report .xls

This is the code I currently have in there:
ActiveWorkbook.SaveAs Filename:= _
"C:\Pipeline Report.xls", _ ....
Could you perhaps tell me how to use a date function in the syntax for the file name assignment?

Thanks for your help.

2007-02-05 23:20:19 · 3 answers · asked by Der Koelner 2 in Computers & Internet Software

3 answers

Use format$ function eg
format$(now(),"YYYY-MM-DD")

2007-02-06 04:16:07 · answer #1 · answered by unnga 6 · 0 0

Here's the command I use:

NewFileName = "My_File_" & Replace (Str (Format(Now, "yyyymmddhhmmss")), " ", "")

I have the date formatted down to hours, minutes and seconds. I do this so that I can save the file as often as I want and get a new file name every time.

Hope this helps!

Regards,
QwertyKPH @ Yahoo!

2007-02-06 05:20:20 · answer #2 · answered by qwertykph 4 · 2 0

sFilename="blah\blah" & now

ActiveWorkbook.SaveAs Filename:= sFilename

Look up the VBA date-time constants to figure out how to get the exact format you want.

2007-02-05 23:29:02 · answer #3 · answered by jshbrnd 2 · 0 0

fedest.com, questions and answers