[英]Opening word template as a template not a document (from Excel)
我正在构建一些报告模板。 它们全部基于具有特定布局和表格的“主模板”。 然后,我有一个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
您可以尝试暂时禁用宏:
tmpAut = wrdApp.Application.AutomationSecurity 'cache current setting
wdApp.Application.AutomationSecurity = msoAutomationSecurityForceDisable
'do your thing here
wdApp.Application.AutomationSecurity = tmpAut 'reset previous
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.