关闭 windows 后结束 Sub 导致 Excel 崩溃,为什么?

End Sub after closing a windows for causes Excel to crash, why?

我的 com-addin 中的以下子程序不会导致任何问题:

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 事件处理程序似乎不是此类调用的最佳位置。