Temporary CommandBar Buttons

P

Peter

How can I change the Visible/Enabled properties of custom toolbar buttons in a template, and silently discard the changes on exit? I'm specifically targeting Word 2000 - 2003.

I am working on a template that has a custom CommandBar with a set of custom buttons (that invoke macros in the template) that I programmatically display/hide/enable/disable based on content in the ActiveDocument. I need the visibility changes to be temporary, or I need some way to programmatically close/save the document without the user being prompted to save changes to the template.

I have also tried adding buttons using Temporary:=True instead of setting the Visible/Enabled properties of existent buttons, but Word still wants to save changes to the template.

I've tried setting CustomizationContext = ActiveDocument, then changing/adding buttons, but that messes up the document, natch.

One of the custom buttons is a "close" button that invokes a macro named "exitApp()", which has one line in it: "Call Application.Quit(SaveChanges:=wdDoNotSaveChanges)". Closing the document via the special "close" button doesn't bring up the "Do you want to save changes to the template?" dialog. Closing the document by clicking on the "X" in the upper right-hand corner shows the template save dialog, so I added the line from exitApp() to the end of the AutoClose macro, to no avail.

Additionally, saving the document brings up a "do you also want to save changes to the template?" dialog.

Any ideas?

-Peter
 
B

Birgit

Hi Peter,
You can stop the question of saving changes to the template by setting the
..saved property of the template to true after making the changes you need to
make. Nothing changed, nothing to save (even if you have made changes). Be
careful: intended changes will not be asked to be saved any more either, so
be sure you save those by hand.

HTH,
Birgit

"Peter" <peterguy -at- hotmail -dot- com> schreef in bericht
How can I change the Visible/Enabled properties of custom toolbar buttons in
a template, and silently discard the changes on exit? I'm specifically
targeting Word 2000 - 2003.

I am working on a template that has a custom CommandBar with a set of custom
buttons (that invoke macros in the template) that I programmatically
display/hide/enable/disable based on content in the ActiveDocument. I need
the visibility changes to be temporary, or I need some way to
programmatically close/save the document without the user being prompted to
save changes to the template.

I have also tried adding buttons using Temporary:=True instead of setting
the Visible/Enabled properties of existent buttons, but Word still wants to
save changes to the template.

I've tried setting CustomizationContext = ActiveDocument, then
changing/adding buttons, but that messes up the document, natch.

One of the custom buttons is a "close" button that invokes a macro named
"exitApp()", which has one line in it: "Call
Application.Quit(SaveChanges:=wdDoNotSaveChanges)". Closing the document
via the special "close" button doesn't bring up the "Do you want to save
changes to the template?" dialog. Closing the document by clicking on the
"X" in the upper right-hand corner shows the template save dialog, so I
added the line from exitApp() to the end of the AutoClose macro, to no
avail.

Additionally, saving the document brings up a "do you also want to save
changes to the template?" dialog.

Any ideas?

-Peter
 
P

Peter

Ah, so simple. :)
Thanks, Birgit, your suggestion addressed my difficulty perfectly.
I had previously done as you suggested, and it didn't work: the "save template?" dialog still popped up on closing/saving the document. However, I think I had not done all the setup correctly prior to changing the buttons (CustomizationContext = ActiveDocument.AttachedTemplate), so setting ActiveDocument.AttachedTemplate.Saved = True had not taken effect.
So, to summarize for anyone else who may be as blind as I can be sometimes; the correct way to make temporary changes to the template is:

CustomizationContext = ActiveDocument.AttachedTemplate
.... Make changes to the buttons/add temporary objects/whatever ...
ActiveDocument.AttachedTemplate.Saved = True

-Peter
 

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