how to name filename with date in macro

D

Daniel M

I have a macro that saves off a copy of a file. i would like to put a date
stamp and/or possibly a time stamp on the filename. Is there anyway of doing
this? thanks.
 
D

Don Guillett

From a recent posting of mine.

Goto the small excel icon in the upper left of the screen next to File>right
click>insert this.
For today, you will get aaa20071116

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim mydate As String
Application.DisplayAlerts = False
mydate = Format(Date, "yyyymmdd")
SaveAs Filename:="aaa" & mydate & ".xls"
Application.DisplayAlerts = True
End Sub
 

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

Top