[英]Execute macro when Word template is attached
I want to run some code when I attach a template to a Word document. 当我将模板附加到Word文档时,我想运行一些代码。
I tried the Document_Open
and Document_New
methods to no avail. 我尝试了Document_Open
和Document_New
方法无济于事。
I also tried the AutoNew
and AutoOpen
method from this article . 我也试过AutoNew
和AutoOpen
从方法这篇文章 。 The AutoOpen method is triggered when I attach my template to the document, close it, and then open the document again. 当我将模板附加到文档,将其关闭,然后再次打开文档时,将触发AutoOpen方法。
How can I trigger a line of code to execute when I attach the template to a document? 将模板附加到文档时,如何触发一行代码执行?
EDIT : Currently we are attaching the template through the Templates
dialog. 编辑:当前,我们通过Templates
对话框附加模板。
We are also adding a button in the ribbon, with the below code, to attach the template. 我们还在功能区中添加一个带有以下代码的按钮,以附加模板。
savedTmplt = "C:\Program Files\*****\template.dotm"
Set q = wd.ActiveDocument
wd.WordBasic.DisableAutoMacros False
With q
.AttachedTemplate = savedTmplt
.UpdateStyles
End With
wd.WordBasic.DisableAutoMacros
Whilst there is an Open event and a New event there is'nt an AttachTemplate event. 虽然有一个Open事件和一个New事件,但没有AttachTemplate事件。 So it simply isn't possible to have code automatically respond to the template being attached. 因此,根本不可能让代码自动响应所附加的模板。
Your options are: 您的选择是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.