如何阻止用户手动关闭 Word 的 VB6 自动实例?

How do I stop the user from manually closing a VB6 automated instance of Word?

我的问题是关于对自动化实例的绝对控制。我正在使用 VB6 来自动生成我们工作场所中使用的表单。该应用程序处于测试阶段,我已经编写了一份用户手册来向新用户介绍该应用程序;解释 GUI 的子功能。我使用 GUI 上的命令按钮在 Word 实例中打开和关闭用户手册。所有这一切都很好,直到用户在应用程序 运行 时手动关闭 Word 应用程序。这会终止 Word 实例,但我需要阻止用户关闭 Word 实例,或者让应用意识到该实例已消失。我的自动化知识很浅。我从 VBA 宏改编子例程。请帮忙。

I need to either stop the user from closing the Word instance, or have the app realize the instance is gone

两者都可以 - 使用 "Give me events" 语法声明 Word 变量,它会在代码中引发 DocumentBeforeClose 事件。

Public WithEvents mWordApp As Word.Application

Sub DoStuff()
    Set mWordApp = New Word.Application
    '// open doc ...
    mWordApp.Visible = True
End Sub

Private Sub mWordApp_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
    Cancel = MsgBox("Word is closing, keep open?", vbYesNo) = vbYes
End Sub

MSOffice Application实例的“... WithEvents ...”声明就是解决这个问题的方法。应用程序的事件列表允许程序员从幕后完全自动控制实例。谢谢大家!