I am manipulating Excel and saving and the 1st save works great, but when it hits the 2nd save I get a com exception of System.RunTime.InteropServices.COMException (0x800A03EC) Exception from HRESULT: 0x800A03EC
I have verified the path is valid, Excel is still open, and Excel is still the active workbook. What should I do to fix this?
private void btn1_Click()
{
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oWS;
string SaveDest = "C:\\ExcelFiles\\Reviewed\\";
string EmailToSup = "C:\\Ready\\";
string localdir = "C:\\ExcelFiles\\";
var cFiles = Directory.EnumerateFiles(localdir, "*.xlsx", SearchOption.TopDirectoryOnly);
foreach (string alpha in cFiles)
{
oWB = (Excel._Workbook)(oXL.Workbooks.Open(alpha));
oWB = oXL.ActiveWorkbook;
oWS = (Excel._Worksheet)(oWB.ActiveSheet);
try { oWB.RefreshAll(); }
catch { }
oWB = oXL.ActiveWorkbook;
oWB.SaveAs(SaveDest + Path.GetFileNameWithoutExtension(oXL.ActiveWorkbook.Name));
oWB = oXL.ActiveWorkbook;
try { oWB.SaveAs(EmailToSup + oXL.ActiveWorkbook.Name); }
}
}