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 %26lt;date%26gt;.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.
Excel VB how to save file including date in a filename?
Use format$ function eg
format$(now(),"YYYY-MM-DD")
Reply:Here's the command I use:
NewFileName = "My_File_" %26amp; 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!
Reply:sFilename="blah\blah" %26amp; now
ActiveWorkbook.SaveAs Filename:= sFilename
Look up the VBA date-time constants to figure out how to get the exact format you want.
song words
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment