Word 2003 CommandBar controls want to save themselves in the wrong template

Add-in Express™ Support Service
That's what is more important than anything else

Word 2003 CommandBar controls want to save themselves in the wrong template
When working on a document based on some other template, the toolbar sometimes likes to try and save itself there instead of Normal.dot 
Mike McGavin




Posts: 38
Joined: 2011-05-31
Hello.

I have a Word addin, which unfortunately still needs to remain backwardly compatible to Word 2003, which I'm handling by providing some CommandBar and Menu customisations. (I'll be really really happy when we can finally drop support for Office 2003!)

I've run into a problem whereby, if a user happens to be working with a document that's attached to a non-standard template (as in not Normal.dot), my add-in tries to save its CommandBar persistency info into that template, instead of into Normal.dot... which is where I think that info should be being saved. Consequently the the user is eventually prompted about saving changes to that template once they close the document.

Until now my add-in's customisations have been encapsulated in a dedicated custom CommandBar, and it's apparently been working alright. The upcoming release, however, has required me to add a new Button to the built-in MailMerge toolbar, and also to the Letters and Mailings Menu. I think this is the change which has resulted in the problem. After some painful sessions with a remote debugging setup, I can see that the moment I call someString = myCommandBarButton.Caption, the .Saved property on the template that's attached to the active document changes from True to False. I could write some code to set it straight back to True to trick Word into thinking the template hasn't changed, but to do so would seem quite dangerous in case the user actually had been meaning to save something to that template.

To reproduce, I'd do something like the following:

* Open Word with my add-in installed. (Word opens with a blank document.)
* Create a new document that's based on a template. (Word displays the document, which is attached to the template.)
* Invoke an action in my add-in, which causes some code to retrieve the caption of the CommandBarButton on the mail merge toolbar.
* Close the document and save changes. (Despite my only ever having interacted with the document, Word also prompts to ask if I also want to save changes to the template that's attached to the document.)

If the template is flagged as Read Only on the file system (as it is in some circumstances), Word doesn't even prompt politely---it just pops up a SaveAs dialog to try and force the user to save another copy of the template in another location.


So now I'm stuck. Does this behaviour point to anything obvious which I might be doing wrong in my CommandBar configuration?


The test VM is running Office 2003 and Windows XP, both with all available updates installed, I'm using Addin Express 7.2.4055.2005.

All my command bars and related controls have Temporary=true, http://www.add-in-express.com/docs/net-commandbar-components.php#command-bars-controls-created-removed. To me this explains why the add-in wants to save adjustments to a template... I'm just confused about why it's not automatically trying to save them to Normal.dot, which is where I thought they should be going.

Thanks for any help.

Mike.
Posted 01 Jul, 2013 19:22:07 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Mike,

That page recommends using Temporary=false for Word command bars and controls. According to our guys, by default Add-in Express saves the commandbars to the current template. You can set ADXAddinModule.InsureCommandBarsSaved=true so that Add-in Express moves them to the Normal template.


Andrei Smolin
Add-in Express Team Leader
Posted 02 Jul, 2013 10:12:51 Top
Mike McGavin




Posts: 38
Joined: 2011-05-31
Hi Andrei.

Sorry for the confusion. It was a typing error in my earlier post, but I'd always had Temporary set to False on all CommandBar controls.

Thanks very much for the tip. I'll investigate using the .InsureCommandBarsSaved property, probably from the AddinInitialize event, as you've suggested.

Mike.
Posted 02 Jul, 2013 21:35:03 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Mike,

May I ask you to let me know about your results please?


Andrei Smolin
Add-in Express Team Leader
Posted 04 Jul, 2013 04:26:53 Top
Mike McGavin




Posts: 38
Joined: 2011-05-31
Hi Andrei. Apologies for the lateness of my response.

I've managed to try setting the .InsureCommandBarsSaved property to 'true' during the AddinModule_AddinInitialize event, but I'm afraid it's had no effect. When I placed a breakpoint on that line and stepped through it, it's turned out that it was already set to 'true'.

If you or others have any further thoughts then I'd appreciate hearing them, but we're less concerned about this issue now.

We've resolved to work around it by simply not trying to customise any of Word's existing Command Bars, and we'll place the button on our own toolbar instead, which appears to work well enough. Ultimately we hope we'll not have to support Office 2003 after this release if we can possibly help it (we hoped the same with our previous release), so with luck that will be enough or now.

Thanks very much for the assistance.
Posted 07 Jul, 2013 23:58:49 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hi Mike,

Mike McGavin writes:
We've resolved to work around it by simply not trying to customise any of Word's existing Command Bars, and we'll place the button on our own toolbar instead, which appears to work well enough.


This is an ideal solution of this problem.

Good luck with your project!


Andrei Smolin
Add-in Express Team Leader
Posted 08 Jul, 2013 05:47:01 Top