Is there a way to see if an Excel Workbook, say DataSheet.xls, is open (in use) or not? I would like to close that Workbook if it is opened.
martin's answer does not work if Excel Application is not currently running. You may want to modifiy the code as following :
static bool IsOpened(string wbook)
{
bool isOpened = true;
Excel.Application exApp;
try
{
// place the following line here :
exApp = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
// because it throws an exception if Excel is not running.
exApp.Workbooks.get_Item(wbook);
}
catch (Exception)
{
isOpened = false;
}
return isOpened;
}
Thank you for your attention. Regards