该事件在创建一个基于模板的文档时发生。仅在 New 事件的过程保存在模板中时,才可运行该过程。
Private Sub Document_New()
有关使用 Document 对象事件的详细内容,请参阅使用 Document 对象的事件。
本示例在建立基于模板的新文档时,提示用户是否要保存所有其他已打开的文档(本过程存储在模板的 ThisDocument 类模块中, 而不是在文档中)。
Private Sub Document_New()
Dim intResponse As Integer
Dim strName As String
Dim docLoop As Document
intResponse = MsgBox("Save all other documents?", vbYesNo)
If intResponse = vbYes Then
strName = ActiveDocument.Name
For Each docLoop In Application.Documents
With docLoop
If .Name <> strName Then
.Save
End If
End With
Next docLoop
End If
End Sub