Word

Automatically Save a Copy of a Document to the A: Drive

Ease of Use

Hard

Version tested with

2002 

Submitted by:

Jacob Hilderbrand

Description:

This macro saves a copy of the active document to the A: Drive. 

Discussion:

You have several documents, and after you save them, you manually save a copy to the floppy A: Drive. This macro will automatically save a copy to the A: Drive for you whenever any document it saved. 

Code:

instructions for use

			

'Place all the code in Normal.Dot 'Place this code is a Class Module named Class1 Option Explicit Public WithEvents App As Application Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean) Dim SaveCopy As VbMsgBoxResult Dim Title As String Dim Prompt As String If Flag = True Then Exit Sub End If Prompt = "Do you want to save a copy to the A: drive?" Title = "Confirm Procedure" SaveCopy = MsgBox(Prompt, vbYesNo + vbQuestion, Title) If SaveCopy = vbYes Then Application.OnTime Now + TimeValue("00:00:01"), "AfterSave" End If End Sub 'Place this code in a Standard Module Option Explicit Public Flag As Boolean Sub AfterSave() Flag = True ActiveDocument.SaveAs FileName:="A:\" & ActiveDocument.Name Flag = False End Sub 'Place this code in the ThisDocument module Option Explicit Dim WdApp As New Class1 Private Sub Document_New() Set WdApp.App = Word.Application End Sub Private Sub Document_Open() Set WdApp.App = Word.Application End Sub

How to use:

  1. Open Word.
  2. Press Alt + F11 to open VBE.
  3. On the left, double-click Normal.
  4. From the menu, choose Insert-Class Module.
  5. Paste the code designated for the class module (see comments in code) in the window at the right.
  6. From the menu, choose Insert-Module.
  7. Paste the code designated for the module (see comments in code above) in the window at the right.
  8. Double click on ThisDocument.
  9. Paste the code designated for ThisDocument (see comments in code above) in the window at the right.
  10. Close the VBE (Alt + Q or press the X in the top right hand corner).
  11. Save and Close Word.
 

Test the code:

  1. Open any Word document.
  2. Hit Save.
 

Sample File:

SaveCopy.zip 8.99KB 

Approved by mdmackillop


This entry has been viewed 168 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express