Ran into something very interesting with Word, Templates and the Word Object Model today.
I have a Word Addin that creates a Word Template on the fly and loads it when Word is loading up.
The template is used to save any modifications (via the Application.CustomizationContext property) to the Word Toolbar that I have to make while running, which is pretty standard stuff for a Word COM Addin.
Under normal circumstances, this arrangement works quite well. But today, I had a client report a problem where when they'd close Word, they'd get a pop up message that Word failed to save my template, because some other process has it open. Further investigation showed that 2 or more instances of Word were being loaded (in the background by another application), and the multiple instances of Word appeared to be what was causing the issue.
Now, most anyone who's had to mess with supporting Word as a programmability platform knows it's not a good scene to encourage multiple instances of Word. It just doesn't work out all that well. But here I was, and the other app was a necessary one for this client, so uninstalling it was not an option.
After quite a bit of poking around, it turns out that Word appears to have a problem, or at the very least, an oversight.
The Word Object Model supports an Application.DisplayAlerts property, that is supposed to turn off message boxes, but it fails to do so in the case when you obtain a Template object and then use the Save method on it.
So even if you're trapping errors on the save, intending to handle them through your code, and even if you've turned off alerts, using the above property, Word will still pop up that warning box. Since my template is a completely background piece of functionality, the last thing I want users seeing is warnings about Word being unable to save it.
And here's the kicker. Since you can't necessarily know whether Word will be successful at saving the template beforehand, there is no way you can determine whether or not you should even attempt to save the template. A classic catch-22.
In the end, I was able to work around this, er, unique, behavior by:
It's not ideal, because, under some very peculiar circumstances, it still might be possible for Word to fail to save the template, and subsequently pop up that warning box. But such is the joy of the Word Object Model!
Remember Me
a@href@title, b, i, strike, strong
Page rendered at Saturday, July 31, 2010 7:14:22 AM (Central Standard Time, UTC-06:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.