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
Sub FileSave() Options.CreateBackup = True ActiveDocument.Save ActiveDocument.Saved = False ActiveDocument.Save End Sub
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.
FileCopy statement copies the file specified by
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
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