Excel COMException 0x800A03EC when user cancels file overwrite

I have code that saves an excel file in a specific location and a file name that cannot be changed by the user. It works great when the file does not exist and saves without saving. If the file already exists and the user selects it, it also works great. The problem occurs when it already exists, and the user cancels the save. This throws a COMException 0x800A03EC. Any ideas?

Help: Microsoft Excel 12.0 Object Library

excelWorkbook.SaveAs(resultsFilePath, XlFileFormat.xlExcel8);
+3
source share
2 answers

Try/Catch, , ? try/catch, , , , , ....

  • ExcelWorkbook.Save() - , . , ...
  • , , SaveAs , Excel , , .

, , . , . , Excel Save().

Save() ) ) SaveAs() ConflictResolution XlSaveConflictResolution.xlLocalSessionChanges

( , , , # , , ...)

+3

:

try
{
   excelWorkbook.SaveAs(resultsFilePath, XlFileFormat.xlExcel8);
}
catch // If you want, you can try and catch the actual exception here
{
   // If it gets here, the user probably cancelled (or something else
   // went wrong) You should handle those cases as needed. In the case
   // of the user cancelling, just do nothing here!
}
+1

Source: https://habr.com/ru/post/1758470/


All Articles