private void Application_WorkbookBeforeClose(Microsoft.Office.Interop.Excel.Workbook workbook, ref bool cancel) { if (!cancel) { OnWorkbookBeforeClose(new WorkbookBeforeCloseEventArgs(workbook.Name, workbook)); PendingRequest = new CloseRequestInfo(workbook.Name, Application.Workbooks.Count); } }
private void Application_WorkbookDeactivate(Microsoft.Office.Interop.Excel.Workbook wb) { if (Application.Workbooks.Count == 1) { // With only one workbook available deactivating means it will be closed PendingRequest = null; OnWorkbookClosed(new WorkbookClosedEventArgs(wb.Name)); } }
private void Application_WorkbookActivate(Microsoft.Office.Interop.Excel.Workbook wb) { // A workbook was closed if a request is pending and the workbook count decreased var wasWorkbookClosed = PendingRequest != null && Application.Workbooks.Count < PendingRequest.WorkbookCount; if (wasWorkbookClosed) { var args = new WorkbookClosedEventArgs(PendingRequest.WorkbookName); PendingRequest = null; OnWorkbookClosed(args); } else { PendingRequest = null; } }