Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2007

Tip: Looking for answers? Try searching our database.

Global Template - not save changes when unload

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ArchieD - 31 Jan 2007 17:21 GMT
Hi All

We have a template that is loaded as a global template when Word is started.
During the course of the session, the template is modified.  When Word closes,
it prompts the user to save the template.  

What we want to achieve is closing Word without that message - the template
should only be modified by the system and then all changes should be dropped.
The user doesn't need to know anything about it.

We have tried the following without success:

1.    Setting the .Saved property of the template to 'true' whenever any
modification takes place.  However, when Word quits, i.e. the template is
unloaded, the message is still displayed.

2.    Using the Application Quit event.  This seems to occur after the save
event and therefore does not do the trick.

3.    DocumentBeforeClose event.  The code in this runs but it still asks the
user whether they want to save the changes.

4.    DocumentBeforeSave event.  I don’t know if this would do the trick but I
just can’t get it to work which is odd as I get the BeforeClose and
DocumentChange events to run.

We are still using Word XP.

I’m sure  we’re making this too complicated.   There just has to be any easy
way to do this!  Doesn’t there?

Thanks for any help.

ArchieD

*************  Code below  *************

The following code is as a result of working through Bill Coan’s article
‘Take Control of Microsoft Word Through Events’ (Thanks, Bill - & apologies
because we’re clearly doing something wrong).

This is the code in the class module ‘clsAppEventHandler’:

Public WithEvents EventSource As Word.Application
   
Private Sub EventSource_DocumentBeforeClose(ByVal Doc As Document, Cancel As
Boolean)
   Application.Templates("C:\MyTemplates\TheTemplate.dot").Saved = True
End Sub

Private Sub EventSource_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As
Boolean, Cancel As Boolean)
   MsgBox "Before Save"
End Sub

Private Sub EventSource_DocumentChange()
   Application.Templates("C:\MyTemplates\TheTemplate.dot").Saved = True
End Sub

This is the code that creates/destroys the event handler - called in AutoExec
& AutoExit

Dim objEventHandler As clsAppEventHandler

Sub CreateEventHandler()
   Set objEventHandler = New clsAppEventHandler
   Set objEventHandler.EventSource = Word.Application
End Sub

Sub DestroyEventHandler()
   Set objEventHandler = Nothing
End Sub
Tony Jollans - 31 Jan 2007 18:14 GMT
You are probably making this more complex than it needs to be. The changes
being made to the global template are done in your code inside it
somewhere - wherever that is, just add .Saved=True after each occasion and
then it will never show as changed.

Signature

Enjoy,
Tony

> Hi All
>
[quoted text clipped - 78 lines]
>    Set objEventHandler = Nothing
> End Sub

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.