LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Workbooks collection is empty even though the some of the document is open

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I forgot my password to open an excel document, how do I open it? chris ohearn Excel Discussion (Misc queries) 1 August 11th 08 02:32 PM
When I open Excel, workbooks open automatically. How can I stop t Rhealbird Excel Discussion (Misc queries) 2 February 23rd 06 10:08 AM
my excel document won't open unless i go file, then open EB500 Excel Discussion (Misc queries) 1 June 3rd 05 06:42 PM
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 Frank Jones Excel Programming 2 June 15th 04 03:21 AM
Workbooks.Open / .Open Text - How do you stop the .xls addition? Dave[_20_] Excel Programming 2 July 31st 03 04:03 AM


All times are GMT +1. The time now is 10:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"