Posted to microsoft.public.excel.programming
|
|
Saving File with name and date
Thanks that exactly what I wanted
"Nigel" wrote:
You could adapt the following to suit......it creates files in the
following format if already in the same path
filename - 2008-10-29.xls
filename - 2008-10-29(1).xls
filename - 2008-10-29(2).xls
etc.....
Dim myPath As String, myFile As String, myExt As String, mySerial As
String
mySerial = ""
myPath = "C:\Test\"
myFile = "filename" & " - " & Format(Date,"YYYY-MM-DD")
myExt = ".xls"
' create output using sequence 1 to n if file already exists
If Len(Dir(myPath & myFile & mySerial & myExt)) 0 Then
Do While Len(Dir(myPath & myFile & mySerial & myExt)) 0
mySerial = "(" & Val(Mid(mySerial, 2)) + 1 & ")"
Loop
End If
ActiveWorkbook.SaveAs Filename:=myPath & myFile & mySerial & myExt
--
Regards,
Nigel
"Novice Lee" wrote in message
...
Is there a way to save the file I am working on (template) with the name
of
the file and the date?
ex. "filename - 2008-10-29.xls"
also, if the name is duplicated, add a number to the end numerically
ex. "filename - 2008-10-29-01.xls"
Thanks
|