需要知道excel工作簿窗口何时关闭

时间:2011-07-05 14:57:00

标签: excel-addins

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

感谢。

2 个答案:

答案 0 :(得分:0)

看一下这个文件: 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

答案 1 :(得分:-1)

您可以处理BeforeClose事件。使用VBA的示例可用here

相关问题