Reply
 
Thread Tools Display Modes
  #1   Report Post  
MED
 
Posts: n/a
Default How do I automatically run a Macro in MS-Word 2003 on File/Save

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.
  #2   Report Post  
Jay Freedman
 
Posts: n/a
Default

MED wrote:
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/...tSavePrint.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).

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org


  #3   Report Post  
Pedro
 
Posts: n/a
Default

Does this work on earlier versions of MS-Office (MS-Word)?
If yes, how far back will this work?

"Jay Freedman" wrote:

MED wrote:
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/...tSavePrint.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).

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org



  #4   Report Post  
Jay Freedman
 
Posts: n/a
Default

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.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

Pedro wrote:
Does this work on earlier versions of MS-Office (MS-Word)?
If yes, how far back will this work?

"Jay Freedman" wrote:

MED wrote:
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/...tSavePrint.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).

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
In typing dates in Word, i.e. "January 12" how do you keep the "1. Carol Microsoft Word Help 2 January 12th 05 08:09 PM
word xp crashes after macros are recorded kharris0405 Microsoft Word Help 3 January 11th 05 10:50 PM
WP Delay Code - Word Equiv Mike G - Milw, WI Microsoft Word Help 6 January 10th 05 04:12 PM
Continuous breaks convert to next page breaks Jennifer Hunt Microsoft Word Help 2 December 30th 04 05:45 PM
How do I convert a cd in word perfect to microsoft word greylady Microsoft Word Help 1 November 23rd 04 07:03 PM


All times are GMT +1. The time now is 05:15 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"