Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello
I am sharing the code to open an excel workbook, but when i am executing the code after MESSAGE BOX 2, multiple instances of excel process gets created in the task manager and the excel application hangs. kindly help MessageBox.Show("1"); Excel.Application excelApp = new Excel.ApplicationClass (); // Creates a new Excel Application //excelApp.Visible = false; // Makes Excel visible to the user. // The following line adds a new workbook //Excel.Workbook newWorkbook = excelApp.Workbooks.Add (Microsoft.Office.Interop.Excel.XlWBATemplate.xlWB ATWorksheet); // The following code opens an existing workbook MessageBox.Show("2"); Excel.Workbook _book; string workbookPath = @"D:\Window Crawler\GenPatchReport \Test Data\Data.xls"; // Add your own path here _book = OpenExcelWorkbook(workbookPath); //Excel.Workbook excelWorkbook = excelApp.Workbooks.Open (workbookPath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); MessageBox.Show("3"); Excel.Sheets excelSheets = _book.Worksheets; string currentSheet = "Sheet1"; Excel.Worksheet excelWorksheet =(Excel.Worksheet) excelSheets.get_Item(currentSheet); MessageBox.Show("4"); Excel.Range excelCell =(Excel.Range) excelWorksheet.get_Range("A1", "A13"); excelCell.Delete(Type.Missing); NAR(excelWorksheet); MessageBox.Show("5"); protected Excel.Workbook OpenExcelWorkbook(string fileName) { try { if (ExcelApp != null) { Excel.Workbook wb; //wb = ExcelApp.Workbooks.Open(fileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); wb = ExcelApp.Workbooks.Open(fileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); if (wb != null) { _sheets = wb.Worksheets; } return wb; } return null; } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); return null; } } private void NAR(object o) { try { System.Runtime.InteropServices.Marshal.ReleaseComO bject (o); } catch { } finally { o = null; } } Thanks Shantanu |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Process will not end from task manager after vba code is over | Excel Programming | |||
Printing leaves EXCEL.EXE process in Task Manager | Excel Discussion (Misc queries) | |||
excel.exe is not terminating from task manager | Excel Programming | |||
Multiple Instances of Excel in WinXP Pro Task Manager | Excel Programming | |||
EXCEL keeps running in task manager | Excel Programming |