OpenWorkbookToAutomate
(
String workbookPath,
Int32 timeoutSeconds
)
{
Debug.Assert( !String.IsNullOrEmpty(workbookPath) );
Boolean bWorkbookClosedByItself = true;
Process oProcess = Process.Start("Excel.exe",
"\"" + workbookPath + "\"");
if ( !oProcess.WaitForExit(timeoutSeconds * 1000) )
{
bWorkbookClosedByItself = false;
try
{
oProcess.Kill();
oProcess.WaitForExit();
}
catch
{
// It's possible that the process exited after WaitForExit()
// returned, in which case the Kill() call will fail. Ignore
// the Kill() failure.
}
}
oProcess.Close();
return (bWorkbookClosedByItself);
}