NewDocument 事件

       

该事件在创建新文档时发生。

Private Sub object_NewDocument(ByVal Doc As Document)

object   在类模块的事件中声明的 Application 类型对象。有关使用 Application 对象的详细内容,请参阅使用 Application 对象事件

Doc   新文档。

示例

本示例在创建新文档时,提示用户是否保存已打开的所有其他文档。为了看到本例的执行效果,本例提供的代码必须保存在类模块中,而且该类中的实例必须正确初始化;有关完成上述任务的指导,请参阅使用 Application 对象事件

Public WithEvents appWord as Word.Application

Private Sub appWord_NewDocument(ByVal Doc As Document)
    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 Documents
            With docLoop
                If .Name <> strName Then
                    .Save
                End If
            End With
        Next docLoop
    End If
End Sub