Automatically insert date into name of flle

  • Thread starter Thread starter M
  • Start date Start date
M

M

Hello,

I am updating a particular file over and over again, and would like to have
it automatically "save as a name with today's date - for example -
title032708.doc today and if use it again tomorrow to save a new version as
title032808.doc

Is there any way to do this?

Thanks!
 
M said:
Hello,

I am updating a particular file over and over again, and would like to have
it automatically "save as a name with today's date - for example -
title032708.doc today and if use it again tomorrow to save a new version as
title032808.doc

Is there any way to do this?

Yes, but you need a macro.

A few things first...

The macro checks if the document has been saved already. If not it exits.
You must save it with a name in a proper folder first. Do not add the date at
this stage.
Then the macro checks if the document has been saved with a date before, if
so, it removes the old date and adds today's date. If not, it just adds the
date.
So, if you use it twice in the same day, you will overwrite a previously
saved file. If this is not desirable, you will need more code to check for
that.

If you have never used macros before, see:
http://word.mvps.org/faqs/macrosvba/CreateAMacro.htm

Here is the macro:

Sub SaveWithDate()

Dim strPath As String
Dim strDate As String
Dim strName As String

With ActiveDocument
If .Path = "" Then
MsgBox "You must first save this document at least once " _
& "before using this function.", vbExclamation, "Cancelled"
Exit Sub
End If
strPath = .Path
strDate = Replace(CStr(Date), "/", "")
strName = Left(.Name, Len(.Name) - 4)
End With

If Right(strName, 8) Like "########" Then
'Already been saved, replace date
strName = Left(strName, Len(strName) - 9)
'Else, never been saved, just add date
End If

ActiveDocument.SaveAs strPath & Application.PathSeparator & strName _
& "_" & strDate & ".doc"

End Sub
 
Back
Top