【发布时间】:2016-04-23 01:46:02
【问题描述】:
我正在尝试编写一个宏,它使用 Word 对象来创建基于 Word 模板文档的 Word 文档。
我在使用 Option Explicit 时遇到了一些困难。没有它,我可以省略 Dim ... 行,但我希望在那里。
这是目前为止的代码:
Option Explicit
Sub PopulateWordDoc()
Dim wApp As Object
Set wApp = CreateObject("Word.Application")
Dim wdDoc As Word.Document ' User-defined type not defined error on this line
Set wDoc = wApp.Documents.Open("C:\path\WordTestTemplateDoc.dotx", ReadOnly:=False)
With wDoc
.Content.Find.Execute FindText:="<Project ID>", ReplaceWith:="This is the project id....."
.SaveAs2 Filename:=("C:\path\NewWordDoc.docx"), FileFormat:=wdFormatXMLDocument, AddtoRecentFiles:=False
End With
结束子
【问题讨论】:
-
你要的叫“早绑定”。您目前正在做的是“后期绑定”。完整的文章可以在这里找到:support.microsoft.com/en-us/kb/245115