Event after save

P

Patricia Shannon

I am using Word 2003.
I have created a macro that gets the filename beginning with the
server/sharename, using the ShareName Property.
It stores it in a document variable. I can then put it in the document,
eg., the footer. (The built-in filename path returns the mapped drive, eg. I:
We want \\ServerName\ShareName )

I have put this macro in the template for these files. I also put a
document_open event macro in ThisDocument of the template.
That is working fine. So I am set up for the existing documents.

But I am having a problem with new documents, or those created with SaveAs.
The filename does not exist until after the new file is saved. For SaveAs,
the filename before the save is the old one.

What is the best way to handle this? If there were an AfterSave event, it
would make things much easier.
Do I have to create my own macros for FileClose, Filesave, FileSaveAs, and
FileSaveAll, and do all that file dialog stuff?
I believe (hope) I can put these in the template, also.

Looking at the Help for "Using Events with the Application Object", I see I
have to Initialize the Declared Object.
It looks as if I can run this one time, and it make the required connections
so things will work when I create, open, and close documents. Or do I
misunderstand this.
 
J

Jean-Guy Marcil

Patricia Shannon was telling us:
Patricia Shannon nous racontait que :
I am using Word 2003.
I have created a macro that gets the filename beginning with the
server/sharename, using the ShareName Property.
It stores it in a document variable. I can then put it in the
document,
eg., the footer. (The built-in filename path returns the mapped
drive, eg. I: We want \\ServerName\ShareName )

I have put this macro in the template for these files. I also put a
document_open event macro in ThisDocument of the template.
That is working fine. So I am set up for the existing documents.

But I am having a problem with new documents, or those created with
SaveAs. The filename does not exist until after the new file is
saved. For SaveAs, the filename before the save is the old one.

What is the best way to handle this? If there were an AfterSave
event, it would make things much easier.
Do I have to create my own macros for FileClose, Filesave,
FileSaveAs, and FileSaveAll, and do all that file dialog stuff?
I believe (hope) I can put these in the template, also.

Looking at the Help for "Using Events with the Application Object", I
see I have to Initialize the Declared Object.
It looks as if I can run this one time, and it make the required
connections so things will work when I create, open, and close
documents. Or do I misunderstand this.

All you need to highjack are FileSave and FileSaveAs.

With FileSave, just check if the ActiveDocument has a Path, if it doesn't,
call FileSaveAs, something like:

'_______________________________________
Sub FileSave()

If ActiveDocument.Path = "" Then
FileSaveAs
Else
ActiveDocument.Save
End If

End Sub
'_______________________________________

'_______________________________________
Sub FileSaveAs()

Dialogs(wdDialogFileSaveAs).Show

'Your Code to create the doc variable

ActiveDocument.Save

End Sub
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
P

Patricia Shannon

Thanks muchly. It works like a charm. For the benefit of other people who
might see this and are at my level of VBA experience, I was able to put it in
a normal VBA module in the template, not in ThisDocument. I didn't need the
event macro stuff.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top