Save VSTO Word 2007 Template application to docx without prompt to save template
Question
Steps to reproduce:
- Create Word 2007 Template Project (Visual Studio 2008 Professional SP1)
- Place DateContentControl on document
- Save, Publish, open .dotx
- Modify DateContentControl, Save
- Click No, Close Word
- Open Saved document, Modify DateContentControl - no more prompts on subsequent saves...
- Change project code, publish, update VSTO app, open .dotx, repeat step 4
How does a Word 2007 Template application allow a user to modify the document without getting prompted on a save?
Solution
Word checks whether the attached template of a document has been modified and prompts whether to save the changes. To avoid such a prompt you could set the Saved
property of the attached templated to true
.
In VBA this would be:
ActiveDocument.AttachedTemplate.Saved = True
OTHER TIPS
Thanks divo.
Here are the 2 lines in C# for VSTO:
Word.Template template = (Word.Template)this.Application.ActiveDocument.get_AttachedTemplate();
template.Saved = true;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow