ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Save As (https://www.excelbanter.com/excel-programming/297671-save.html)

Orf Bartrop

Save As
 
How would I go about saving a workbook to another name that contains the
date and time? Let's say the original file is called "Book." What I
would like to do is have a macro that saves "Book" as "Book-yy-mm-dd-hh-mm"
Any suggestions?


Dave Peterson[_3_]

Save As
 
One way:

Option Explicit
Sub testme01()

Dim myName As String

With ActiveWorkbook
myName = .Name

myName = Application.Substitute(LCase(myName), ".xls", "") & _
"_" & Format(Now, "yyyy-mm-dd-hh-mm")


.SaveAs Filename:=.Path & "\" & myName

'.SaveCopyAs Filename:=.Path & "\" & myName
End With

End Sub

Take a look at .savecopyas in VBA's help. You'll see that it makes a backup of
the file without saving the current file--or changing its name. (It may be
useful--one day?)

Orf Bartrop wrote:

How would I go about saving a workbook to another name that contains the
date and time? Let's say the original file is called "Book." What I
would like to do is have a macro that saves "Book" as "Book-yy-mm-dd-hh-mm"
Any suggestions?


--

Dave Peterson



All times are GMT +1. The time now is 04:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com