The Amazing Disappearing Templates Act

As reported in the VSTO Newsgroup (can' and on Julie's blog, if you try and access ThisApplication.Templates.Count from VSTO, you end up with only one ( instead of the n (where n > 1) entries you were expecting.

I finally got off my lazy body part and did a quick test, and the explanation / solution is pretty simple. It seems that when you boot Word with a document on the command line, it doesn't open any templates in the STARTUP folder. Since this is how VSTO launches your projects for debugging (winword.exe c:pathtoyourdocument.doc) you only ever see one template.

Just to prove to the non-believers that it wasn't some voodoo CLR magic that made the templates disappear <g> I also verified this with VBA, and VBA only sees one template in this scenario too.

If you boot Word normally (from the Start menu) and then manually open the document, everything works fine. You could also modify the Project Properties of your solution to just boot Word when you start debugging, and then manually open the document (which should be in your MRU list, anyways).

Comments (0)

Skip to main content