Revert to Saved





Revert to Saved

figs/beginner.gif figs/hack5.gif

Most other word processors and layout programs put a Revert to Saved command right on the File menu. This allows for a quick return to the last saved version of a file. This hack shows you how to add this feature in Word.

While editing a document, you make a mistake. A big mistake. You try the Undo command a few times, but you can't quite retrace your steps. In frustration, you close the document without saving your changes, then reopen it. This is a minor annoyance, but it may be something you have to do a lot. Fortunately, there's an easier way.

1 The Code

To put a Revert to Saved option on your File menu, add this macro to Normal.dot:

Sub FileRevertToSaved( )

Dim sDocPath As String

Dim sDocFullName As String



sDocFullName = ActiveDocument.FullName

sDocPath = ActiveDocument.Path



If Len(sDocPath) = 0 Then

    MsgBox "Can't revert a document that's never been saved."

    Exit Sub

End If



If MsgBox("Really revert to last saved version? " & _

          "(Can't be undone)", _

           vbYesNo) = vbNo Then

   Exit Sub

End If



Documents.Open FileName:=sDocFullName, Revert:=True

End Sub

2 Putting the Macro in Your File Menu

Select ToolsCustomize and click the Commands tab. Choose Normal.dot from the "Save in" drop-down list. In the Categories list, select Macros, and in the Commands list, select the new FileRevertToSaved macro, as shown in Figure.

Selecting a macro from the Customize dialog
figs/wrdh_0210.gif


Next, drag the macro to the File menu, as shown in Figure. After you place it in the menu, you can right-click it and shorten its name to "Revert to Saved." Since you stored this customization in Normal.dot, close and restart Word to prevent losing the change in case of a crash.

Adding the Revert to Saved macro to the File menu
figs/wrdh_0211.gif


The macro will notify you if you try to revert a document that hasn't yet been saved (and, of course, won't revert anything). It also asks for confirmation before reverting, as shown in Figure.

The Revert to Saved macro asks for confirmation before running
figs/wrdh_0212.gif



     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows