4

i got a urgent problem with the following error, while setting the DisplayAlerts-property of the Excel ApplicationClass to false.

var excel = new Excel.Application();
excel.DisplayAlerts = false;

I get the following error message in the logs:

System.Runtime.InteropServices.COMException (0x800AC472): Exception from HRESULT: 0x800AC472
     at Microsoft.Office.Interop.Excel.ApplicationClass.set_DisplayAlerts(Boolean RHS)
     at Service.Dispose()

The following MessageBox is shown


(source: xlam.ch)

Any ideas on this case?

Regards MacX

Community
  • 1
  • 1
MacX
  • 587
  • 5
  • 16

2 Answers2

0

I think you should call DisplayAlerts on the instance of Excel.Application you're working with. Something like this:

var excel = new Excel.Application();
excel.DisplayAlerts = false;
Paolo Falabella
  • 24,914
  • 3
  • 72
  • 86
  • @MacX then see [this thread](http://social.msdn.microsoft.com/forums/en-US/vsto/thread/9168f9f2-e5bc-4535-8d7d-4e374ab8ff09/). Basically they advise to wait and retry your call after a second when you get that error... – Paolo Falabella Mar 09 '11 at 13:55
  • you're kidding. that's no real fix for this prob – MacX Mar 09 '11 at 14:12
  • @MacX yes, not a very exciting answer, I'm afraid... I hope someone can suggest a better solution – Paolo Falabella Mar 09 '11 at 16:44
0

You'll have to catch that error and re-submit whatever you were inserting into a cell on excel. This is an annoying bug and I have not been able to implement and elegant solution for.

Someone can correct me if I am wrong but I cannot find a way to determine if Excel is in a "suspended" state or not besides catching this exception. It's like an unavoidable race condition where you don't know the result until you know the result. I searched for a way to solve this before giving up and implemented an ugly error checking solution.

Sorry, I hope someone has a better solution for this than me.

Chase
  • 564
  • 7
  • 22