将指定模板作为文档打开并返回一个 Document 对象。
注意 将模板作为文档打开则允许编辑该模板的内容。当 Template 对象中的某属性或方法(例如 Styles 属性)无效时,就可能需要使用这种方法。
expression.OpenAsDocument()
expression 必需。该表达式返回一个 Template 对象。
本示例打开活动文档所选用的模板,如果该模板包含了不止一个段落标记的内容,则显示一个消息框,然后关闭该模板。
Dim docNew As Document
Set docNew = ActiveDocument.AttachedTemplate.OpenAsDocument
If docNew.Content.Text <> Chr(13) Then
MsgBox "Template is not empty"
Else
MsgBox "Template is empty"
End If
docNew.Close SaveChanges:=wdDoNotSaveChanges
本示例为常用模板保存一个副本“Backup.dot”。
Dim docNew As Document
Set docNew = NormalTemplate.OpenAsDocument
With docNew
.SaveAs FileName:="Backup.dot"
.Close SaveChanges:=wdDoNotSaveChanges
End With
本示例改变活动文档所选用的模板中“标题 1”的样式设置。UpdateStyles 方法用来更新活动文档中的样式。
Dim docNew As Document
Set docNew = ActiveDocument.AttachedTemplate.OpenAsDocument
With docNew.Styles(wdStyleHeading1).Font
.Name = "Arial"
.Size = 16
.Bold = False
End With
docNew.Close SaveChanges:=wdSaveChanges
ActiveDocument.UpdateStyles