返回介绍

DocumentOpen 事件

发布于 2019-09-29 10:21:58 字数 977 浏览 1054 评论 0 收藏 0

该事件在文档打开时发生。

Private Subobject_DocumentOpen(ByValDoc As Document)

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

Doc 将打开的文档。

示例

本示例在文档打开时,提示用户是否要保存所有其他已打开的文档。 为了看到本例的执行结果,本例提供的代码必须保存在一个类模块中,而且该类中的实例必须正确初始化;有关完成上述任务的指导,请参阅使用 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文