End Subclosures窗口后导致Excel崩溃,为什么?

在我的COM插件下面的子不会导致任何问题:

Private Sub MonthCalendar1_DateChanged(sender As Object, e As Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged Dim ExcelApp As Excel.Application = CType(AddinExpress.MSO.ADXAddinModule.CurrentInstance, AddinModule).ExcelApp ExcelApp.ActiveCell.Value = MonthCalendar1.SelectionStart.Date End Sub 

下面的子然而,我已经添加Me.Close()语句,导致Excel崩溃。 可能是什么原因?

 Private Sub MonthCalendar1_DateChanged(sender As Object, e As Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged Dim ExcelApp As Excel.Application = CType(AddinExpress.MSO.ADXAddinModule.CurrentInstance, AddinModule).ExcelApp ExcelApp.ActiveCell.Value = MonthCalendar1.SelectionStart.Date Me.Close() End Sub 

编辑:也许我的代码触发一些其他事件在我的代码执行,并导致Excel崩溃? 是否有可能在任何事件开始时暂停执行? 由于我不知道哪个事件可能会被调用,我不知道在哪里添加断点。

改用Hide方法。 看来DateChanged事件处理程序不是这种调用的最佳位置。