Even if you’re using the macros earlier in the chapter to save your work frequently, you can still lose data if your hard drive crashes. So we’ve all learned from hard experience not only to save our work regularly, but also to make periodic backup copies. The macro I use most often in Word is one that does both in a single procedure! That is, the macro not only saves your work, but it also makes a backup copy on another drive, such as a removable disk, a second hard drive, or a network folder. Listing 1 shows the code.
Listing 1 A Procedure That Creates a Backup Copy of the Active Document on Another Drive


The backupFile and currFile variables are strings that store the full pathnames for the active document and the backup version of the document. Use the BACKUP_FOLDER constant to specify the folder in which you want the backup stored.
The procedures first check to see if the backup operation is necessary. In other words, if the document has no unsaved changes (the Saved property returns True) or if it’s a new, unsaved document (the Path property returns “”), bail out of the procedure (by running Exit Sub).
Otherwise, a new Bookmark object is created to save the current position in the document, screen updating is turned off, and the file is saved.
We’re now ready to perform the backup. First, the currFile variable is used to store the full pathname of the document, and the pathname of the backup file is built with the folÂlowing statement:
backupFile = BACKUP_FOLDER + .Name
This is used to save the file to the specified folder. The actual backup takes place via the SaveAs method, which saves the document to the path given by backupFile. From there, the procedure closes the backup file, reopens the original file, and uses the GoTo method to return to the original position within the document.
TIP
Using a Bookmarkobject to reset the insertion point is useful because it takes you back to the exact point in the document where you were before the backup started. However, you may be interested only in returning to the last position within the document where an edit occurred. If that’s the case, use the following statement in place of the Selection.GoTo statement:
Application.GoBack
Note, however, that there’s a bug in the GoBackmethod, whereby Word doesn’t save the last edit position (technically, it’s a hidden bookmark named \PrevSel1) in some cases. Specifically, when you exit Word, if you elect to save changes in the last document that gets closed, Word doesn’t save the last edit position in that document.
Technorati Tags: making backup, word 2007
Popularity: 3% [?]








November 19th, 2008 at 8:14 pm
great tip, im using hibernater, will be better if hibernater can implement this.