When exiting Excel Application in Windows Forms, the parent form closes too

Viewed 7

I am using Microsoft.Office.Interop.Excel to open an excel application within a panel. However, whenever I close Excel in the panel, it closes the parent form as well. Currently using a button to open excel in the panel, but not sure how to keep the parent form open when excel is closed.

private void button1_Click_1(object sender, EventArgs e)
        {
            excelApp = new Microsoft.Office.Interop.Excel.Application();

            excelApp.Visible = true;
            excelApp.ScreenUpdating = true;
            excelApp.EnableAutoComplete = false;
            object misValue = System.Reflection.Missing.Value;
            excelWorkBook = excelApp.Workbooks.Add(misValue);
            IntPtr excelHwnd = new IntPtr(excelApp.Application.Hwnd);
            SetParent(excelHwnd, pnl_ProjectDoc.Handle);
            excelApp.WindowState = XlWindowState.xlMaximized;
        }
0 Answers
Related