【发布时间】:2016-01-19 13:19:02
【问题描述】:
我正在编写一些 VBA 代码(在 Excel 中)以在工作中自动生成报告。这些报告需要具有特定格式,可通过我们的公司模板轻松获得。这一切都在 MS Office 2010 中。
但是,所有这些模板都有Document_New() subs,这会引发一些我不想启动的 VBA 代码,遗憾的是无法直接访问(公司规则,该死的!)。
有没有办法覆盖Document_New() 宏?现在,我用于打开文档的 VBA 代码(触发 Document_New() 宏)如下:
Sub GenerateReport()
Dim WordApp As Object
Set WordApp = CreateObject("Word.Application")
WordApp.Documents.Add Template:="Letter.dot" ' the "error" is produced at this lie
Dim SaveStr As String
SaveStr = "KommRapp-" & Date & ".docx"
WordApp.ActiveDocument.SaveAs SaveStr
End Sub
【问题讨论】: