|
|
|
|
|
|
Many people access the material from this web site daily. Most just leech what they want and run. That's OK, provided they are not selling on the material as their own; however if your productivity gains from the material you have used, a donation from the money you have saved, however small, would help to ensure the continued availability of this resource.
Click the
appropriate button above
to access PayPal. |
|
Automatically backup Word documents
|
|
|
Contrary to
popular opinion, Word has no integral means of automatically saving the
current document, nor of backing-up the current document. What it does
have is an option to save AutoRecover information after a specific and
configurable interval and an option to save a backup copy of the
previously saved version of the document with the default file
extension of WBK (and although there is no reason to do so, Word also
allows the option to change this extension to the user's choice). This is
not a true backup in as much as it is not a copy of the current version
of the document.
AutoRecover
provides the basis to recover a document (or part of it) in the event of a
system crash, but is somewhat hit or miss and should not be relied upon to
save your bacon. |
|

or in Word 2007

and

|
|
There is a
macro available with Word that will provide an auto save function called
SaveReminder This is also
available for download from this site via the above link.
This provides
options to both remind you to save, or to automatically save either the
current or all open documents. |
|




|
| Save document to two locations |
|
The way to
achieve a true backup is to save the document to two separate locations,
however, because of the way Word creates temporary files in the workspace,
and the unpredictability of the document size, these locations must
never be on removable media - particularly floppy discs. Saving to
such media is one of the main causes of document corruption (and thus loss
of your work!). There are macros later on this page which can be used for
creating duplicate files on removable media, but the essential process
is to SAVE the file to the hard drive then COPY the resulting document
to the alternative location.
You cannot copy
a document that is open, so the following macro closes the document
before coping then re-opens it again with the cursor located at the same
place as it was when the macro was run..
Sub
SaveToTwoLocations()
Dim oDoc As
Document
Dim strFileA As
String
Dim strFileB As
String
Dim strBackupPath As
String
'Define the backup location
strBackupPath = "D:\My Documents\Word Backup\"
On Error Resume Next
Set oDoc = ActiveDocument
With oDoc
'Mark the cursor position with a bookmark
.Bookmarks.Add Range:=Selection.Range, name:="OpenAt"
.Save
strFileA = .FullName
strFileB = strBackupPath & "Backup " & .name
.Close 'Close the document
End With
FileCopy strFileA, strFileB 'Copy the document
Documents.Open strFileA 'Reopen the original
document
ActiveWindow.View.Type = wdPrintView
'and restore the cursor position
ActiveDocument.Bookmarks("OpenAt").Select
End Sub
The following version allows the user to select the
backup location each time the macro is run
Sub
SaveToTwoLocationsB()
Dim oDoc As
Document
Dim strFileA As
String
Dim strFileB As String
Dim strBackupPath As String
Dim fDialog As FileDialog
Set fDialog =
Application.FileDialog(msoFileDialogFolderPicker)
On Error GoTo CancelledByUser
'Get the folder for the backup location
With fDialog
.Title = "Select folder to save the copy and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1
Then
MsgBox "Cancelled By
User", , "Save to Two Locations"
Exit Sub
End If
strBackupPath = fDialog.SelectedItems.Item(1)
End With
On Error Resume Next
Set oDoc = ActiveDocument
With oDoc
'Mark the cursor position
with a bookmark
.Bookmarks.Add Range:=Selection.Range, name:="OpenAt"
.Save
strFileA = .FullName
strFileB = strBackupPath & "\Backup " &
.name
.Close 'Close the document
End With
FileCopy strFileA, strFileB 'Copy the document
Documents.Open strFileA 'Reopen the original
document
ActiveWindow.View.Type = wdPrintView
'and restore the cursor position
ActiveDocument.Bookmarks("OpenAt").Select
Exit Sub
CancelledByUser:
MsgBox "Cancelled by User"
End Sub
If you don't
know how to use macros from web site listings, see the
linked installation information.
This macro is best called from a toolbar button. It cannot, as it stands,
be used to replace the default 'Save' function which it uses itself,
though you could certainly call it from the toolbar icon
or you could
re-assign the CTRL+S keyboard shortcut to the macro.
In my own installation, I have two 'Save' icons (see below). The left is
the original - the right (re-coloured with the customization tools
) calls
the macro.
|
|
Note: |
You could copy this image and paste it to your Word 2000/2003 toolbar command if you
wish.
With
Word 2007, you could add the macro command to your QAT (Quick Access
Toolbar), but you will be limited to the available icons or you can
create an add-in template with a custom toolbar in Word 2000/3
containing the commands you want and save that in the Word 2007 start-up
folder. |
| |


|
| |
The macro uses the FileSave function to save the document, and allow you
to name the document if a new document. The name is then stored and the
document saved to the defined backup location - D:\My Documents\Word
Backup\ in this example - though the code may easily be changed to
reflect your own preference.
Having saved the document to the backup
location, the Word focus is on the backed up version. To correct this,
without the delay of closing and re-opening the required version of the
document, the document is saved again to the original location.
|
| Note: |
This also has the effect of
updating the automatic backup file (filename.WBK) to make that a true
backup, thus you have two backup files if this option has been set. |
| Save a backup and copy to
removable media |
|
|
The following macro is a variation on the version above, inspired by a
question posed in Microsoft's newsgroup forums. A user wanted to backup
his documents to one of two locations - depending on whether it was an
odd or even date - and to copy the document to a flash drive.
The macro
saves the document in its original location then makes a backup in one
of two locations
D:\My Documents\Test\Versions\Odd
or
D:\My Documents\Test\Versions\Even
highlighted in the code in a bold blue
typeface.
The document is then closed and
the file copied to the flash drive - here shown with the drive letter
H: and then finally the original
document is re-opened. You can change the file locations to suit your requirements.
In addition
the backup copies have the month and date of the backup appended to the beginnings
of the filenames. |
| Note: |
This
method could be used to copy to a floppy
drive, however Word documents can have a file size of many megabytes and
the space available on a floppy drive is strictly limited.
If the
disc is available but will not accommodate the file, the filename will
be created and the error routine will activate. This will delete
the corrupt partial file, but will mean that any file with that name,
that previously existed on the removable medium, will be lost. |
| |
Sub CopyToFlash()
Dim strFileA As
String
Dim strFileB As
String
Dim strFlash As
String
Dim strBackupFolder
As String
With ActiveDocument
.Save 'Save the original document
strFileA = ActiveDocument.FullName
'Store original document name
'Select flash drive letter. Default is H
strFlash = InputBox("Enter Flash Drive Letter", "Flash
Drive", "H")
strFlash = strFlash & ":\" & .name
'Store flash drive filename
' Set backup alternative
folder for odd and even dates
If Even = (Day(Now)
Mod 2) - 1 Then 'It's
an odd date
strBackupFolder = "Odd\"
Else
'It's an even date
strBackupFolder = "Even\"
End If
'Add full path to backup
folder and date to filename
strFileB = "D:\My
Documents\Test\Versions\" _
& strBackupFolder & Format$(Date, "MMM d ") _
& .name
.SaveAs FileName:=strFileB, AddToRecentFiles:=False 'save
backup in the appropriate folder
.Close 'close the backup document
End With
On Error GoTo oops
'Trap copy error
FileCopy strFileA, strFlash 'Now copy document to
flash drive
Documents.Open strFileA 'Re-open the original
document
ActiveWindow.View.Type = wdPrintView
End
oops:
If Err.Number = 61
Then 'Flash drive is full error
MsgBox "Disc Full! The partial file created will be
deleted", vbExclamation
Kill strFlash
Else 'Other error
MsgBox "The flash drive is not available",
vbExclamation
End If
Documents.Open strFileA 'Re-open the original document
ActiveWindow.View.Type = wdPrintView
End Sub |
| Save a copy of the current
document to flash |
| |
The following is a simpler version of the above macro, which merely
copies the active document to a flash drive, subject to the same warning
above relating to the use of floppy media.. |
| |
Sub
SaveACopyToFlash()
Dim strFileA As
String
Dim strFlash As
String
strFlash = InputBox("Enter Flash Drive Letter", "Flash Drive", "H")
If
strFlash = "" Then
MsgBox "User Cancelled", vbExclamation, "Cancelled"
Exit Sub
End If
With ActiveDocument
.Save 'save the original document
strFileA = .FullName 'Saved original
document name
strFlash = strFlash & ":\" & .name
'Flash drive filename
.Close 'Close the document
End With
On Error GoTo oops
'Error handler for missing flash drive
FileCopy strFileA, strFlash 'Copy source to flash
Documents.Open strFileA
ActiveWindow.View.Type = wdPrintView
End
oops:
If Err.Number = 61
Then
MsgBox "Disc Full! The partial file created will be deleted",
vbExclamation
Kill strFlash 'Remove the partial file
Else
MsgBox "The flash drive is not available", vbExclamation
End If
Documents.Open strFileA
ActiveWindow.View.Type = wdPrintView
End Sub
|
|