Saving A Duplicate - Word 2003

P

Peter Noneley

Hi,

Word 2003

I have created a macro to save a file and have a duplicate saved at
the same time.

The duplicate is saved in a different folder, and has the date and
time included as part of the filename.

The code works, but I'm sure it can be improved.

My questions are:

(1) Can I prevent the duplicate from being included in the Most
Recently Used files list?

(2) Are there any other improvements I could make to the code?

Thanks

Peter

---------------------------------------------------------------------------------------
Sub SaveDuplicate()

'This macro saves the current document in two places.
'The original is saved as usual and a duplicate copy is saved to a
different folder.
'The duplicate has the same filename, but with the Date and Time
included in the filename.
'For example, for a file named "MEMO", the duplicate would be "MEMO
2010-01-01 09-54-28.doc"

Dim strDuplicateTime As String
Dim strDuplicatePath As String
Dim strDuplicateName As String
Dim strOriginalName As String

'Remember the original File name and Path of the doc to be saved.
strOriginalName = ActiveDocument.FullName

'Get the current Date and Time. These will form part of the duplicate
file name.
strDuplicateTime = Format(Now, " yyyy-mm-dd hh-mm-ss")

'This is the folder I will be using to save my duplicates.
strDuplicatePath = "C:\MyDuplicates\"

'This picks out just the Filename, without the Path or Extension.
strDuplicateName = Left(ActiveDocument.Name, Len(ActiveDocument.Name)
- 4)

'Save the Duplicate file.
ActiveDocument.SaveAs FileName:=strDuplicatePath & strDuplicateName &
strDuplicateTime

'Save the original file.
ActiveDocument.SaveAs FileName:=strOriginalName

End Sub
---------------------------------------------------------------------------------------
 
D

Doug Robbins - Word MVP

To stop the duplicate being added to the MRU, use:

ActiveDocument.SaveAs FileName:=strDuplicatePath & strDuplicateName & _
strDuplicateTime, AddToRecentFiles:=False

It might be better to use

strDuplicateName = Left(ActiveDocument.Name, Instr(ActiveDocument.Name,
".") - 1)

to deal with differing length extensions, as will occur if you move to Word
2007 or 2010
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
P

Peter Noneley

To stop the duplicate being added to the MRU, use:

ActiveDocument.SaveAs FileName:=strDuplicatePath & strDuplicateName & _
strDuplicateTime, AddToRecentFiles:=False

It might be better to use

strDuplicateName = Left(ActiveDocument.Name, Instr(ActiveDocument.Name,
".") - 1)

to deal with differing length extensions, as will occur if you move to Word
2007 or 2010
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com






















- Show quoted text -

Doug,

Thank you.

Both suggestions have worked perfectly.

My original docs get saved to a network, but I like to use this macro
when working on important stuff. I save about every 5 minutes. Its
just a precaution in case the doc becomes corrupted, I can go back to
one of the duplicates.

Peter
 

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