Help please - adding a button from template code, asks to save a template

A

Alexey Titov

Hello :)

I have a template with code in it that creates new command bar button for
current doc:

(code in template)

Private Sub Document_New()

Set objCommandBar = ActiveDocument.CommandBars("Standard")
Set objCommandBarButton_1 = objCommandBar.Controls.Add(msoControlButton,
, , 1, True)
objCommandBarButton_1.Style = msoButtonCaption
objCommandBarButton_1.Caption = "Command 01"

....

Private Sub Document_Close()

objCommandBarButton_1.Delete - not actually needed as button being added
as Temporary, but result is the same


when I create a new doc based on this template and then close it - it asks
me if I want to save the doc itself and then - the template too :(
I've checked - it asks to save temlate only if I add that command bar
button.
But I add it as a temporary button, and then even if I try to delete that
button on document close - it still asks me to save the template.
How do I make it not to ask about saving the template?

TIA
Alexey
 
G

Gordon Bentley-Mix

Alexey,

This behaviour is expected. Even though the template looks the same at the
end as it did at the beginning, the very act of adding a button to a toolbar
makes the template "dirty" - even if you subsequently delete the button
again. (In fact, deleting the button also makes the template "dirty".)

The easiest way around this is to simply add the line

ActiveDocument.AttachedTemplate.Save

to your Document_Close code.

You may also want to specify the CustomizationContext for the CommandBar to
ensure that the Normal template is affected by your changes.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 

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