Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I have a requirement to check if an excel document is open or closed from another C# application. For this, I am using Automation to get the instanc of the Excel application and iterating through the WorkBooks collection. The problem is sometimes the Workbooks collection returns empty collection and so I could determine if the document is open or not. Some time it works correctly with the same environment. Here is my code snippet I am using. if(excelApp == null) { try { excelApp = (Excel.Application)Marshal.GetActiveObject("Excel. Application"); } catch(System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } if (excelApp == null) return null; } foreach(Excel.Workbook book in excelApp.Workbooks) { try { if (book.FullName.ToLower() == m_strFileName.ToLower()) { return book; } } catch(System.Exception ex) { //You will get the exception here if the application is busy/ RMLogger.Error(ex); return null; } } Any help is highly appreciated. Thanks Thanga |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
I forgot my password to open an excel document, how do I open it? | Excel Discussion (Misc queries) | |||
When I open Excel, workbooks open automatically. How can I stop t | Excel Discussion (Misc queries) | |||
my excel document won't open unless i go file, then open | Excel Discussion (Misc queries) | |||
Excel 2003 Workbooks.Open with CorruptLoad=xlRepairFile fails on Excel 5.0/95 file due to Chart, with Error 1004 Method 'Open' of object 'Workbooks' failed | Excel Programming | |||
Workbooks.Open / .Open Text - How do you stop the .xls addition? | Excel Programming |