Macro for Word file backups

J

John

I'd like to write a macro that saves my current file with its filename
followed by the date and time. For example, if the file is called Test.doc
and the date and time is 25 Feb 2004, 10:33pm, the backup file would be
called Test_040225_2233.doc. The current file name after running the macro
must still be Test.doc, so if the nomal save command is used, the current
document is still saved to Test.doc. Any ideas?
 
J

Jezebel

Your macro needs to:

1. Save the current document
2. Save as your new name
3. Close
4. Re-open the original


To create you file name you can use:

pFileName = Left(ActiveDocument.Name, len(ActiveDocument.Name)-4) &
format(Now, "yymmdd") & "_" & format(Now, "hhnn")
 
W

Word Heretic

G'day "John" <[email protected]>,

with ActiveDocument
Original = .name
..Saveas Original & Date$...
..Saveas Original
end with


Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


John reckoned:
 
J

John

Thanks Jezebel + Word Heretic.

I combined your suggestions to get this and it worked:

Sub FileBackup()
With ActiveDocument
Original = .Name
pFileName = Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 4) &
"_" & Format(Now, "yymmdd") & "_" & Format(Now, "hhnn")
.SaveAs pFileName
.SaveAs Original
End With
End Sub

Improvements I'd like to make are:
1) It saves my current document and my backup files in the c:\ directory,
but I want them all to be stored in the folder that the current document
used to be stored in.
2) I'd prefer not to save my current document with the macro.

Does anyone have any ideas?

Thanks again,

John.
 
W

Word Heretic

G'day "John" <[email protected]>,

1) ActiveDocument.Fullname or
options.DefaultFilePath(wdCurrentFolderPath) & ...

2) Not really possible if I understand you correctly.


Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


John reckoned:
 
J

John

What I mean is that I don't want the macro to actually save the current
document with it's original name (eg test.doc) but only to do a save as for
the backup file (eg test_040227_2018.doc). I only want test.doc saved with I
use CTRL-S, or the other stardard methods of saving a document which are not
part of this macro.
 
W

Word Heretic

G'day "John" <[email protected]>,

IF it has an original name, then it has to have been saved already, so
saving again is irrelevant. If you use Jez's suggestion and re-open
the original to restore the name, rather than re-saving, you lose all
updates since the last change. You HAVE to do things this way :)

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


John reckoned:
 
W

Word Heretic

G'day "John" <[email protected]>,

WHEW! Sometimes you wonder if it's just you going crazy or whether the
orig poster was REALLY barking up the wrong tree :) Gald to have been
of some help mate

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


John reckoned:
 

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