Excel 在关闭 Windows 窗体时锁定

本文关键字:窗体 锁定 Windows Excel | 更新日期: 2023-09-27 18:37:01

使用C#,我正在开发一个Excel加载项。此加载项打开一个 Windows 窗体,需要将ScreenUpdating设置为 false,因此我使用以下代码。

using Excel = Microsoft.Office.Interop.Excel;
[...]
ExcelApp = Globals.ThisWorkbook.ThisApplication;
ExcelApp.ScreenUpdating = false;

到目前为止,这工作正常。但是,关闭表单时Excel锁定,我不知道为什么。删除以下行时,关闭表单成功。

ExcelApp = Globals.ThisWorkbook.ThisApplication;
ExcelApp.ScreenUpdating = false;

Excel 在关闭 Windows 窗体时锁定

在关闭表单之前设置ExcelApp.ScreenUpdating = true;可以解决问题。