开发者

Changing AttachedTemplate property of Word.Document object places previously attached template in edited state

开发者 https://www.devze.com 2023-02-10 16:13 出处:网络
Using a Word Addin, we wish to attach a document to a particular template as soon as it is opened, which we do by setting the property of the document to the path of the template:

Using a Word Addin, we wish to attach a document to a particular template as soon as it is opened, which we do by setting the property of the document to the path of the template:

objDoc.AttachedTemplate = "C:\PathToTemplate\template.dot"

However, in so doing, the template previously attached to the document (i.e. normal.dot) is placed in an edited state, leading to a prompt to save changes to that template when Word exits if another instance of Word has also changed that normal template.

To be absolutely clear: if Word exits before th AttachedTemplate property is set, Word does not prompt the user to save changes to the template. It is only the act of setting that property that places the (now unattached) template in an edited state.

Setting the Saved property to true prior to setting the AttachedTemplate...

objDoc.AttachedTemplate.Saved = True

...has no effect whatsoever.

If we instantiate a Word.Template type object and set it to the CustomisationContext property prior to setting the AttachedTemplate to our custom template and then set the saved property of that t开发者_如何学Pythonemplate object to true...

Set OldContext = objWord.CustomizationContext
objDoc.AttachedTemplate = "C:\PathToTemplate\template.dot"
OldContext.Saved = True

...then Word still prompts the user to save changes to normal.dot on exit.

This seems to be an intractable problem with a Word customisation add in editing the attached template without it actually doing anything in code that should edit it.

All help and advice gratefully received.


It is CustomizationContext that is causing the change to normal.dot/normal.dotx here - you'll need to set it differently. See http://msdn.microsoft.com/en-us/library/aa537165(office.11).aspx (In particular, the Important box under Design-Time Customizations of Menus, Toolbars, and Keyboard)

0

精彩评论

暂无评论...
验证码 换一张
取 消