简体   繁体   English

将.docm模板应用于MS Word中的现有.doc / .docx文件,可以吗?

[英]Applying a .docm template to existing .doc/.docx files in MS Word, is it possible?

I have a VB.NET program which opens word documents, performs a mail merge and then saves them to a different location. 我有一个VB.NET程序,该程序可打开Word文档,执行邮件合并,然后将其保存到其他位置。 I am now attempting to allow the user to decide when they want to save the document via adding a button to the ribbon in word which calls a macro to do this. 现在,我试图通过添加一个按钮给功能区中的单词(它调用宏来执行此操作)来允许用户决定何时保存文档。

I've created a docm template which adds the button to the ribbon in Word 2007/2010/2013. 我创建了一个docm模板,该模板将按钮添加到Word 2007/2010/2013中的功能区。 On attempting to open any doc/docx file however Word will always open it in a new window which lacks the ribbon modification imposed by the template. 但是,在尝试打开任何doc / docx文件时,Word始终会在没有模板强加的功能区修改的新窗口中打开它。

I was wondering if anybody knew of a way to programmatically apply a template to an existing document short of opening the docm file and pasting in all the text from the doc/docx file? 我想知道是否有人知道一种方法,只需打开docm文件并粘贴doc / docx文件中的所有文本,即可以编程方式将模板应用于现有文档?

If I understand you correctly, the macro (button) is part of the template and is visible as far as the currently open document is using/based on that template. 如果我理解正确,则宏(按钮)是模板的一部分,并且在当前打开的文档正在使用/基于该模板的范围内是可见的。 So, opening an existing document based on another template (that doesn't define the macro) will not show the macro button. 因此,基于另一个模板(未定义宏)打开现有文档将不会显示宏按钮。 "Applying a new template to an existing documents" doesn't really makes sense because templates have their role only when a new document is born. “将新模板应用于现有文档”实际上没有任何意义,因为模板仅在新文档诞生时才发挥作用。 At that moment all styles, content gets copied from the template into the new document and after that any connection with the template is lost . 那时,所有样式,内容都将从模板复制到新文档中,此后,与模板的任何连接都将丢失

I do not see other solution for you other than creating an Application level Add-In for MS Word . 除了为MS Word创建应用程序级别的加载项外,我看不到其他解决方案。 Your clients will have to install the Add-In but after that the required functionality will be always accessible from the Ribbon. 您的客户将必须安装加载项,但之后始终可以从功能区访问所需的功能。 Of course this solution is a more expensive one compared to your current one because you will have to create an Add-In application (not so difficult) as well as installer (MSI setup) for the Add-In (can be difficult without any previous exepriences). 当然,与您当前的解决方案相比,该解决方案要贵一些,因为您将必须创建一个插件应用程序(不是那么困难)以及该插件的安装程序(MSI安装程序)(如果没有以前的版本,可能会很困难)经验)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM