views:

299

answers:

0

I've written an application that converts 1000s of Excel documents into PDFs (I know this is a slow method, but I'm not worried about speed), using the same technique as this, but for Excel instead of Word.

I had the requirement to add the following code:

book.ResetColors();

This is on the Workbook object. For the majority of cases this works fine, but for some of the files I get the following error (irrelevant bits emitted):

Exception from HRESULT: 0x800A03EC
System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC
   at Microsoft.Office.Interop.Excel.WorkbookClass.ResetColors()

If I do the same thing using an Excel Macro in VBA, I get this error:

Run-time error '1004':

Method 'ResetColors' of object '_Workbook' failed

There is no macro code inside the spreadsheets themselves. The only thing that seems to be common is they have a large number of sheets.

Has anyone come across this before, and do you know of a good work around? My only thought at the moment is detecting the error and converting the file manually (yuck). Ideally I'm hoping there is something in the API that can be used to determine if this method call will fail. I looked on Google and couldn't find anything useful.