Global Template - not save changes when unload

  • Thread starter ArchieD via OfficeKB.com
  • Start date
A

ArchieD via OfficeKB.com

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
 
T

Tony Jollans

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.
 

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