Application.DocumentOpen 事件 (Word)

在打开文档时发生。

语法

表达式DocumentOpen (Doc As Document**)

表达 一个变量,表示使用类模块中的事件声明的“Application”对象。

参数

名称 必需/可选 数据类型 说明
Doc 必需 Document 即将打开的文档。

备注

有关对 Application 对象使用事件的详细信息,请参阅 对 Application 对象使用事件

示例

此示例询问用户是否在打开文档时保存所有其他打开的文档。 此代码必须放置在类模块中,并且必须正确初始化 类的实例才能看到此示例的工作原理;有关如何完成此操作的说明 ,请参阅将事件与 Application 对象配合使用

Public WithEvents appWord as Word.Application 
 
Private Sub appWord_DocumentOpen(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

另请参阅

Application 对象

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。