Save File with Date and Time Stamp

  • Thread starter Thread starter Andibevan
  • Start date Start date
A

Andibevan

Hi All,

How do I save a file with a date and time stamp?

I need the filename to include BOTH the date and the time?

Thanks

Andi
 
Activeworkbook.SaveAs Filename:= Format(now,"yyyy-mm-dd hh:mm" )

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Andi, something like this,

Sub Save_As()
ActiveWorkbook.SaveAs Filename:="Test " & Format(Now,
"mm-dd-yyyy-hh-mm") & ".xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False
End Sub


--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2002 & 2003
 
Hi Andibevan

Try this

Sub test()
Dim strdate As String
strdate = Format(Now, "dd-mm-yy h-mm-ss")
With ActiveWorkbook
.SaveAs "C:\" & strdate & ".xls"
End With
End Sub
 
Cheers All

Ron de Bruin said:
Hi Andibevan

Try this

Sub test()
Dim strdate As String
strdate = Format(Now, "dd-mm-yy h-mm-ss")
With ActiveWorkbook
.SaveAs "C:\" & strdate & ".xls"
End With
End Sub
 
Is it possible to include a ":" between "the hour" and "the minute" in
time stamp used as part of a filename (file to be saved by VBA code)?
Normally, VBA will not allow this.

Thanks for a response,
Chuckles12
 
Windows won't allow colons in the file name.

I use the underscore (_) as a separator if I really want one.
 
How would I properly insert the underscore (_). When it saves it saves like
20060503-2006_05_03-162230.xls
this is how I have it written, how can I change it to save like
2006_05_03-162230.xls

With ActiveWorkbook
.SaveAs Left(ActiveWorkbook.FullName, _
InStr(1, ActiveWorkbook.FullName, "-")) _
& Format(Now, "yyyy(_)mm(_)dd-hhmmss") & ".xls"
End With

Dave Peterson said:
Windows won't allow colons in the file name.

I use the underscore (_) as a separator if I really want one.
 
Dim mySuffix as string
mysuffix = format(now,"yyyy_mm_dd-hhmmss") & ".xls"

I think???
How would I properly insert the underscore (_). When it saves it saves like
20060503-2006_05_03-162230.xls
this is how I have it written, how can I change it to save like
2006_05_03-162230.xls

With ActiveWorkbook
.SaveAs Left(ActiveWorkbook.FullName, _
InStr(1, ActiveWorkbook.FullName, "-")) _
& Format(Now, "yyyy(_)mm(_)dd-hhmmss") & ".xls"
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top