Save As wýth date and time

O

Opinicus

In the Excel group someone posted a macro for saving an Excel worksheet with
the date and time automatically appended.

Is there a way to do a similar thing in Word? When the macro is run it will
save a copy of the file with the current name (basename) but with the date
and time appended thus for example:

basename yymmdd hhmm

TIA
 
G

Graham Mayor

You need something along the lines of the following, which will save a timed
and dated copy (in the requested format) in the folder defined in
strBackupPath. This must be a valid folder name. If you set strBackupPath =
"" the backup copy will be saved in the current folder. The original
document remains the active document. The macro should work with doc and
docx formats. See also http://www.gmayor.com/automatically_backup.htm

Sub SaveATimedCopy()
Dim strFileA As String
Dim strFileB As String
Dim strFileC As String
Dim strBackupPath As String
strBackupPath = "D:\My Documents\Test\"
With ActiveDocument
.Save
strFileA = .Name

If Right(strFileA, 1) = "x" Then
strFileB = Left(strFileA, Len(strFileA) - 5) & _
Chr(32) & Format(Date, "yyMMdd") & _
Chr(32) & Format(Time, "hhmm") & ".docx"
Else
strFileB = Left(strFileA, Len(strFileA) - 4) & _
Chr(32) & Format(Date, "yyMMdd") & _
Chr(32) & Format(Time, "hhmm") & ".doc"
End If
strFileB = strBackupPath & strFileB
strFileC = .FullName
.SaveAs FileName:=strFileB
.SaveAs FileName:=strFileC
End With
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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