Adding temporary popup menu to custom toolbar makes it prompt to save my template

Adding temporary popup menu to custom toolbar makes it prompt to save my template

Post by Gee » Sat, 01 May 2004 09:29:37


I am adding a popup menu to my custom menu with code with some dynamic menus
under it. I specify the Temporary equals true but it is like it sometimes
saves when I am designing it and also keeps prompting me to save the
template when I close word. Is there a way to ensure it does not ask me to
save it when it is in production and to ensure the menu is cleared when I do
save it.
 
 
 

Adding temporary popup menu to custom toolbar makes it prompt to save my template

Post by Peter Hewe » Sat, 01 May 2004 10:05:30

Hi Gee

Because you're adding your menu(s) dynamically it always dirties the template. This in
turn causes Word to ask you if you want to save the changes.......

Try the following:

Public Sub FileSave()
If ActiveDocument.Type = wdTypeTemplate Then
' Delete your menu(s)
End If
ActiveDocument.Save
End Sub

This will get around the problem of accidentally saving the menu(s) with your template.
Also in the code that adds the menu(s), immediately after add the following line:
ThisDocument.Saved = True

This will stop Word from prompting "Do you want to save changes......"

HTH + Cheers - Peter


"Gee" < XXXX@XXXXX.COM >, said:

 
 
 

Adding temporary popup menu to custom toolbar makes it prompt to save my template

Post by Charles Ke » Sat, 01 May 2004 10:17:57

Except ActiveDocument.Save
will save any changes the user may have made to the template before the code
was run without asking (as well as any changes made by other dirty Add-Ins).
Undoing the changes and marking the template as saved will avoid that, but
will then not save any user-made changes or prompt for those either.
Possibly getting the saved status before running the code then restoring
that status after undoing the changes would come closest to clean code. Just
some thought from a non-expert.
--

Charles Kenyon

Word New User FAQ & Web Directory: http://www.yqcomputer.com/

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

See also the MVP FAQ: http://www.yqcomputer.com/ !
--------- --------- --------- --------- --------- ---------
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.




template. This in
your template.
following line:
menus
to
do
 
 
 

Adding temporary popup menu to custom toolbar makes it prompt to save my template

Post by Peter Hewe » Sat, 01 May 2004 11:34:22

Hi Charles Kenyon

Said <Except ActiveDocument.Save
will save any changes the user may have made to the template before the code
was run without asking (as well as any changes made by other dirty Add-Ins).>

It does *not* alter the behavior of the equivalent File>Save in any way (except for
deleting the menus if the user is editing the template). Whether the template is clean or
dirty or not is not the responsibility of the macro to determine.

If Gee wants to preserve the templates saved status then that's a no brainer:
Dim boolSaved as Boolean

boolSaved = ActiveDocument.Saved
' Kill the menu(s)
ActiveDocument.Saved = boolSaved

As for <will save any changes the user may have made to the template before the code
was run without asking>. When did FileSave ever "ask" for anything except a file name
(using the Save As dialog) if the Documents not been previously saved?

The code will do exactly what Gee wants without introducing any additional problems of is
own. If the template's (open as a document) is dirty when FileSave is run how's it
supposed to determine how the template was dirtied!

Cheers - Peter


"Charles Kenyon" < XXXX@XXXXX.COM >, said:


HTH + Cheers - Peter
 
 
 

Adding temporary popup menu to custom toolbar makes it prompt to save my template

Post by Charles Ke » Sat, 01 May 2004 12:07:17

i Peter,

What is the purpose of running FileSave at all if the code has cleaned up
after itself. Setting the saved status to true gets rid of any annoying
prompt.

The purpose of preserving the saved status is to keep the status quo, as if
the procedure had not run or dirtied the template. I am thinking in terms of
a user having asked to save style changes to a template or adding AutoText
on the one hand (changes the user wants saved) and having a style
automatically saved because of a bad setting (when the user does not want it
saved) on the other hand. In the latter situation, when the document is
closed, the user will be prompted as to whether he/she wants to save changes
to the document template. That is when the user is asked, not by FileSave
but by closing the attached document.

I don't want my Add-Ins or templates saving changes I made (deliberately or
inadventently) without asking. I also don't want them throwing away changes
that I made without asking, either. Code can throw away changes that the
code made without asking. Guess I'm picky.

Generally I don't have my Add-Ins make changes in the UI through code,
because my pickiness makes it a bother to clean up. That is a limitation.
--

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

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
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.

"Peter Hewett" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
code
Add-Ins).>
(except for
template is clean or
brainer:
before the code
a file name
problems of is
how's it
code
Add-Ins).
but
Just