2

我正在工作并使用 excel 插件,我需要打开同一工作簿的新窗口以在不同的工作表中输入数据。对于新窗口,我需要知道窗口何时关闭,以便对输入的数据进行一些验证。有没有办法知道工作簿窗口何时关闭?

谢谢。

4

2 回答 2

1

看看这个文档: http: //support.microsoft.com/kb/213566

创建一个模块和一个类模块。代码如下。

类模块代码:

Public WithEvents appevent As Application

Dim windowsCount As Integer


Private Sub appevent_WindowActivate(ByVal Wb As Workbook, ByVal Wn As Window)
If windowsCount <> Application.Windows.Count Then
    MsgBox "You closed a window"
End If
End Sub


Private Sub appevent_WindowDeactivate(ByVal Wb As Workbook, ByVal Wn As Window)
windowsCount = Application.Windows.Count
End Sub

模块代码:

Dim myobject As New Class1


Sub Test()

Set myobject.appevent = Application

End Sub

这个工作簿的处理程序:

Private Sub Workbook_Open()
Test
End Sub
于 2011-09-08T17:18:26.790 回答
-1

您可以处理BeforeClose事件。此处提供了使用 VBA 的示例。

于 2011-07-05T15:00:19.110 回答