打开Word模板作为模板而不是文档(来自Excel)

我正在构build一些报告模板。 它们都是基于一个具有特定布局和表格的“主模板”。 然后,我有一个Excel表,我正在使用填充主模板,然后另存为一个新的模板,报告该特定的项目。 我有这个工作正常,但意识到我的代码打开一个新的基于主模板的文件,然后保存为新的模板。

这很好,但是我的主模板现在在Document_New()事件中包含一个用户窗体。 因此,我需要它作为一个模板打开,所以我可以填充和保存为新的模板。 通过代码打开主文档而不是模板,它将立即运行用户表单。 我需要它让我打开主,填充它并保存它,然后,当需要做报告时,打开新的模板,然后运行用户表单。

我的代码(在Excel文件中)打开主模板是:

Dim wdApp As New Word.Application 'a new instance of Word Dim wdDoc As Word.Document 'our new Word template Dim myWordFile As String 'path to Word template myWordFile = "W:\Entity\Inspect\WORD\INSPECTION TEMPLATES\Inspection Template - 20160519.dotm" wdDoc.SaveAs "W:\Entity\Inspect\WORD\INSPECTION TEMPLATES\Report Templates\" & vUnit & "\" & vItem & " Thorough Examination.dotm", wdFormatXMLTemplateMacroEnabled wdApp.Documents.Close 

您可以尝试暂时禁用macros:

 tmpAut = wrdApp.Application.AutomationSecurity 'cache current setting wdApp.Application.AutomationSecurity = msoAutomationSecurityForceDisable 'do your thing here wdApp.Application.AutomationSecurity = tmpAut 'reset previous