locked
VSTO Word Template & Custom Menus/Toolbars Best Practices RRS feed

  • Question

  • Hi,

    Case #1. I have created a blank new Word Template project in VSTO 2005. When I run it, a new Word document is created basing on my template. The problem is that although my project is purely blank and also I do nothing with the Word document, the save prompt occurs when I attempt to close the Word document, saying "Do you want to save the changes to MyTemplate.dot?" I believe you can easily repro this.

    Case#2. While I've been waiting for an answer, I tried the "PowerPoint Deck Generator" sample, part of the MSDN. Surprisingly, the DOT file coming with this sample doesn't cause the above save prompt problem. I played with it in many ways trying to understand what is the difference between this DOT and my original DOT, but I couldn't find any. Finally, I just copied sample DOT to MyTemplate.dot and it worked for me.

    Now I have another problem. Until now, I've been thinkning that the best practice to create static Word custom toolbars and menus for an add-in is in design time, in a DOT file that is then included into the delivery. With VSTO, I thought that the bundled MyTemplate.dot is the perfect candidate for it.

    However, any custom stuff I create in MyTemplated.dot is not shown when the solution starts :(. It is only visible if I open MyTemplate.dot for editing, but not when I create new documents from the template. I experimented with the original DOT file (which causes the above save prompt trouble) and I found that it *does* show the custom toolbars and menus. Troubles are never really gone!:)

    Can you explain me the following:

    1) Why the save DOT prompt occurs in case #1 and not in the case #2?

    2) Why the custom bars are shown in the case #1 and not in the case #2?

    3) What is the best practice to create custom toolbars and menus in VSTO solutions?

    Sorry for the long post, this is a complex question. Thanks!



    Thursday, August 10, 2006 8:41 AM

Answers

  • #1

    I'm not familiar with the sample file you mention, but generally it's a good idea to put
       this.InnerObject.Saved = true; //for a document

      this.InnerObject.AttachedTemplate.Saved = true; //for a template

    in the code. Sometimes, it's enough to put it at the end of the Startup procedure. Depending on what all your code does in the background, it may need to be added elsewhere, as well.

    #2

    There's really no definitive answer for this. Best is simply to add code to the Startup procedure that explicitly sets the Visible property of commandbars you're concerned about to true.

    #3

    This really depends on each individual project and its requirements. As a general rule, though, since the CommandBar controls in VSTO need to be linked to event procedures at runtime anyway (unlike in a template that works with internal VBA), it's just as well to generate them at run-time.

    Thursday, August 10, 2006 9:15 AM