How do I automatically run a Macro in MS-Word 2003 on File/Save

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to update the date and version of a document by using a macro
which I would like to run everytime the author saves the revised document.
How do I get the macro to run "Everytime" the File/Save or File/Save As is
requested.
 
MED said:
I am trying to update the date and version of a document by using a
macro which I would like to run everytime the author saves the
revised document. How do I get the macro to run "Everytime" the
File/Save or File/Save As is requested.

You need to write macros named FileSave and FileSaveAs. These macros will
automatically intercept the menu and toolbar commands (see
http://word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm).

In each macro, you do your processing and then invoke the built-in
procedure. For example,

Public Sub FileSave()
' do your processing here

ActiveDocument.Save
End Sub

Public Sub FileSaveAs()
' do your processing here

On Error Resume Next
Dialogs(wdDialogFileSaveAs).Show
End Sub

This may not be quite enough. If the user clicks the File > Save As command
and then clicks Cancel in the dialog, the macro will have already done the
version processing. There's a way to program around this. If you need to
pursue this more, please post in the programming newsgroup
(microsoft.public.word.vba.beginners).
 
Does this work on earlier versions of MS-Office (MS-Word)?
If yes, how far back will this work?
 
Hi Pedro,

It works in all versions from Word 97 (the first one that contained VBA
instead of WordBasic) to the current Word 2003. Word 95 and earlier
versions don't understand VBA at all.

Depending on what you do in the "your processing here" portion, you may need
to use some different code there for Word 97 (in which VBA was based on VB
5.0) than in later versions (based on VB 6.0). However, that has no direct
relation to the mechanism for intercepting menu commands.
 
Back
Top