0

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); }
  }
}
Big Pimpin
  • 427
  • 9
  • 23
  • [Related, possible duplicate](http://stackoverflow.com/questions/1981395/windows-7-net-excel-saveas-error-exception-from-hresult-0x800a03ec) - does anything in there help at all? If not, there are other results on [this search](https://www.google.co.uk/search?q=0x800A03EC+Excel._Workbook+save) that may be useful – James Thorpe Apr 17 '15 at 19:57
  • @JamesThorpe - that doesn't help me. The problem is, the exact lines of code work great in one project, but this is a new project and it will not work in the new project. – Big Pimpin Apr 17 '15 at 20:02
  • Are the paths in both projects the same? Other results indicate this error may be a permissions issue, does the process have access to write to "c:\ExcelFiles\Reviewed" (so the first one works) whilst it doesn't have permissions to write to "c:\ready"? – James Thorpe Apr 17 '15 at 20:19
  • Google "excel save error 1004". Three hundred thousand hits ought to cover it, you don't need another one. – Hans Passant Apr 17 '15 at 20:38

0 Answers0