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.

Re: Event after save by Jean-Guy

Jean-Guy
Mon Sep 11 21:53:14 CDT 2006

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
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org



Re: Event after save by PatriciaShannon

PatriciaShannon
Tue Sep 12 08:20:02 CDT 2006

Thank you very much. That's not as bad as I thought.

"Jean-Guy Marcil" wrote:

> 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
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org
>
>
>

Re: Event after save by PatriciaShannon

PatriciaShannon
Fri Sep 22 08:43:02 CDT 2006

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.

"Jean-Guy Marcil" wrote:

> 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
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org
>
>
>