I have following code that does a name check in a worksheet collection and return true if that worksheet has been found.
foreach (Excel.Worksheet sheet in xlApp.Worksheets)
{
if (sheet.Name.Equals("myXlSheet"))
{
resultWorkSheet = (Excel.Worksheet)xlApp.Worksheets.Item["myXlSheet"];
return true;
}
}
For some reason, xlApp.Worksheets
would give 0x800A03EC Error sometimes. It doesn't seem to happen all the time though. And I can't reproduce the same error in development environment, which really baffles me.
So what's problem here? Any good ideas or suggestions? Thanks.