save a global template automaticaly

A

AirW

I have created a custom Global Template and added it to the startup
folder in Word. It is loaded correctly - and performs its actions well
(only some toolbar manipulation firing several macros. The toolbar
belongs to this template - none of the others are touched).

Buttons on it are pushed down and up (they act like toggle buttons)
But they are all permanent - and not created or any other new
properties assigned (other than catching their being clicked and
up/down)

Whenever the Word instance is closed (and hence the template is closed)
and if (and only if) one of those toggle buttons has been clicked,
there is a prompt to "Save Changes to XXXX.dot". (Where that's the
template name). The prompt comes after the last document has been
closed, and before Word closes.

Actually it doesn't matter if the custom Global template is saved or
not as only the statuses of the button (BtnUp or BtnDown) will be
saved for the next session, but many employees are confused and unsure
what they should answer.

I've looked for an event of the application object to save (autoclose,
autoexit, save_before closing, etc.), but they don't seem to be able to
trap this request.

I just want to trap the message or to save the global template
automaticaly.

Thanks for any thoughts.

Air W
 
R

Robert Paulsen

I wouldn't wait until the Word session ends. Write a routine that saves the
template, and just call it at the end of each toolbar button macro. This way
after the toggle sets the template to unsaved, the macro sets it back to
saved and no message appears on the exit of Word.
 
C

Charles Kenyon

Unless you want to save these changes in button state between Word sessions
why save? Simply add a line to your code that marks your template's saved
state as true.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
A

AirW

Hi Robert!
I thought of that already. The problem is adressing the right document.
I do want the user to be able to save his work normaly.

"ThisDocument.Saved = True" would not work

"ActiveDocument.AttachedTemplate.Saved = True" is no good either
because global templates are not attached.
"NormalTemplate.Saved" is a read only propertie.

Actually when I close the last document, the Word window is empty (no
document open). but the tool bar is there, then I close word and the
message appears.

I tried to split the work: only the button functions togherer with the
toolbar on Normal.dot and the rest of the macros on my global template
and it works fine (as long as the auotmatic saving of normal.dot
option is activated).But I want only one template!

Air W
 
C

Charles Kenyon

ThisDocument.Saved = True
will work. Try it.
ThisDocument is the template containing the code (and the buttons).
ActiveDocument is the user's document.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
T

Tony Jollans

ThisDocument.Saved should, as Charles says, work - unless you have renamed
it. More generally this will always work ...

Set MyTemplate = Templates(MyToolBarButton.Parent.Context)
MyTemplate.Saved = True

(where MyToolBarButton is a reference to the toolbar button you are changing
the state of)
 
A

AirW

Yeah !

One Line of code works wonder!

I can save the document and wenn Word closes It doesn't bother me.
great

for the sake of it here is the button code
Public Function setButton(btnCaption As String, btnState As Integer)
' Purpose: reset all buttons up and push down the selected button (with
appropriate caption)
' Makro aufgezeichnet am 10.04.04 von Hervé Larroque

Dim cmdButton As CommandBarButton
On Error Resume Next

For Each cmdButton In CommandBars("InterSprachen").Controls

If cmdButton.Caption = btnCaption Then

cmdButton.state = btnState
Else
cmdButton.state = msoButtonUp

End If
Next cmdButton

'This mark the template as saved to bypass the «Do you want to save
this template» message,

ThisDocument.Saved = True

End Function
 
A

AirW

Hi Tony !

Problem solved (after two days), but what is exactly "ThisDocument" ?

In the project window I see:

Normal - which is the Normal.dot I suppose.
and
Normal (my Macro name)

They both contain a folder "Microsoft Word Object" an a file
"ThisDocument"

Which is which?:

Regards

Air W
 
C

Charles Kenyon

Just to be clear. Make sure the customization context for your function is
your template. From the way you describe the actions, I expect that it is.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.


Yeah !

One Line of code works wonder!

I can save the document and wenn Word closes It doesn't bother me.
great

for the sake of it here is the button code
Public Function setButton(btnCaption As String, btnState As Integer)
' Purpose: reset all buttons up and push down the selected button (with
appropriate caption)
' Makro aufgezeichnet am 10.04.04 von Hervé Larroque

Dim cmdButton As CommandBarButton
On Error Resume Next

For Each cmdButton In CommandBars("InterSprachen").Controls

If cmdButton.Caption = btnCaption Then

cmdButton.state = btnState
Else
cmdButton.state = msoButtonUp

End If
Next cmdButton

'This mark the template as saved to bypass the «Do you want to save
this template» message,

ThisDocument.Saved = True

End Function
 
C

Charles Kenyon

ThisDocument is whatever document or template contains the code being run.
(Usually a template.) Every document or template can be ThisDocument, but
only one will contain the code being run. For the code being run, it is the
document or template that has the code.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
T

Tony Jollans

You have two Normals? Unless you have deliberately done this - and I can't
imagine why - and I doubt, anyway, given the questions you are asking - I
presume you have created your template by copying (the original) normal.dot
and renaming it. I would advise against this - normal is not a normal
template (if you see what I mean) - it holds things that other templates
don't, so at the very least you are likely to have some bloat - and I
wouldn't be at all surprised if it caused other problems.

To answer your question as simply as I can ...

Every Document (and Template) has an associated Code Module which, by
default, is called "ThisDocument" but can be renamed.

The name of this code module is (automatically) set up as a 'global'
property and it can be used in code anywhere in any module within that
document or template to refer to the document (or template) unequivocally
and without having to hard code (or even know) the actual name. It's not
100% foolproof but it comes pretty close.
 
A

AirW

Hi Tony!

I started to write this macro back in 1999 with Word 97. I was young
and innocent then.
Anyway, it work very good until now. But I may copy it as a real global
macro just in case.
Thanks for the advice

Air W.
 

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