在打开文档时发生。
语法
表达式。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
另请参阅
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。