MS Word

Double-Save a Document

Call me paranoid, but I think Word may really be out to get meor perhaps it's just that I'm working with master documents. Anyway, Word seems unstable, and I want to keep a backup copy of each document I'm working with while I'm working with it. It seems to me that Word's automatic backup copy would be just about ideal, if it were a copy of my most recent save rather than the last-but-one save. With the speed at which I'm trying to make progress on my documents, even losing a couple of minutes' worth of changes is painful.

Create a macro to force Word to save the document twice in immediate succession. Call the macro FileSave so that it replaces Word's built-in Save command and picks up its keyboard shortcut (Ctrl+S).

If you simply want to double-save the document, all you need is the macro shown in Example 8-9.

Macro to save the active document twice in succession

Example 8-9
  Sub FileSave()
     Options.CreateBackup = True
     ActiveDocument.Save
     ActiveDocument.Saved = False
     ActiveDocument.Save
  End Sub

The Options.CreateBackup = True statement ensures that the "Always create backup copy" feature is on (you can also set it by choosing Tools » Options, clicking the Save tab, and checking the "Always create backup copy" box).

But if you really need to safeguard your work, you can adapt the macro so that it automatically copies the backup document to a safe locationfor example, a network drive, as in Example 8-10.

This macro declares three String variables to store the text it uses for naming the documents. It assigns to strDocName the name of the active document and assigns to strWordBackupDoc a string consisting of the full name (including the path) that Word gives the backup document for the active document. For example, if the active document is named Example.doc and is located in the C:\Samples folder, its backup document is named C:\Samples\Backup of Example.wbk.

The macro assigns to strMyBackupDoc the path and name for the backup document that you want to create. In this example, the macro assigns the backup document the path Z:\Publi-c\Backups\ (change it as needed, and use the notation \\server\folder\ if the drive isn't mapped to a letter), the basic filename, the word "backup," the date in yyyy-mm-dd format, and the time in hh-mm-ss AMPM format. In other words, the backup document for Example.doc will have a name such as Example backup 2005-05-27 04-14-38 PM.doc.

Finally, the FileCopy statement copies the file specified by strWordBackupDoc to strMyBackupDoc. If there's already a file with that name in the backup folder, it will be overwritten, but unless you save twice within a second, this shouldn't happen.

Macro to backup the active document's default backup copy to a network drive

Example 8-10
 Sub FileSave()
    Dim strDocName As String
    Dim strWordBackupDoc As String
    Dim strMyBackupDoc As String
    Options.CreateBackup = True
    ActiveDocument.Save
    ActiveDocument.Saved = False
    ActiveDocument.Save
    strDocName = ActiveDocument.Name
    strWordBackupDoc = ActiveDocument.Path & "\Backup of " & _
       Left(strDocName, Len(strDocName) - 3) & "wbk"
    strMyBackupDoc = "Z:\Public\Backups\" & Left(strDocName, _
      Len(strDocName) - 4) & " backup " & Format(Date, "yyyy-mm-dd") & _
      " " & Format(Time, "hh-mm-ss AMPM") & ".doc"
    FileCopy strWordBackupDoc, strMyBackupDoc
  End Sub