更改 Word.Document 对象的 AttachedTemplate 属性会将先前附加的模板置于已编辑状态

发布于 2024-10-17 06:36:42 字数 890 浏览 1 评论 0原文

使用 Word 插件,我们希望在打开文档后立即将其附加到特定模板,这是通过将文档的属性设置为模板的路径来实现的:

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

但是,这样做时,之前附加到的模板文档(即normal.dot)处于已编辑状态,如果Word 的另一个实例也更改了该普通模板,则在Word 退出时会提示保存对该模板的更改。

需要绝对明确的是:如果 Word 在 AttachedTemplate 属性设置之前退出,Word 不会提示用户保存对模板的更改。只有设置该属性的行为才能将(现在未附加的)模板置于编辑状态。

在设置 AttachedTemplate... 之前将 Saved 属性设置为 true

objDoc.AttachedTemplate.Saved = True

没有任何效果。

如果我们实例化一个 Word.Template 类型对象并将其设置为 CustomizationContext 属性,然后将 AttachedTemplate 设置为我们的自定义模板,然后将该模板对象的已保存属性设置为 true......

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

则 Word 仍会提示用户退出时将更改保存到 normal.dot。

这似乎是一个棘手的问题,因为 Word 自定义添加在编辑附加模板时没有实际在代码中执行任何应该编辑它的操作。

非常感谢所有的帮助和建议。

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 template 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一笑百媚生 2024-10-24 06:36:42

正是 CustomizationContext 导致了此处对 normal.dot/normal.dotx 的更改 - 您需要对其进行不同的设置。请参阅 http://msdn.microsoft.com/en-us /library/aa537165(office.11​​).aspx(特别是菜单、工具栏和键盘的设计时自定义下的重要框)

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文