Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
In typing dates in Word, i.e. "January 12" how do you keep the "1. | Microsoft Word Help | |||
word xp crashes after macros are recorded | Microsoft Word Help | |||
WP Delay Code - Word Equiv | Microsoft Word Help | |||
Continuous breaks convert to next page breaks | Microsoft Word Help | |||
How do I convert a cd in word perfect to microsoft word | Microsoft Word Help |