Making Backups as You Work in Word 2007

Microsoft Word, Tips & Tricks Add comments

mswordtweak.pngEven 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

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: ,

Popularity: 3% [?]

Related Post

  • Making Backups in Access 2007
  • Testing Action Queries (Carefully) in Access 2007
  • Ensuring Consistent Document Formatting in Word 2007
  • Recovering More of Your Work with a Shorter AutoRecover Interval in Word 2007
  • Change the Default Open and Save As Folders
  • Don't Find What You're Looking For? Please Try Here...

    Google
     

    One Response to “Making Backups as You Work in Word 2007”

    1. zhiyang Says:

      great tip, im using hibernater, will be better if hibernater can implement this.

    Leave a Reply

    WP Theme & Icons by N.Design Studio
    Entries RSS Comments RSS Add to Technorati Favorites Log in