Five year old piece of code suddenly fails.

How many times have you just thrown something together, put it in the wild, expecting to never hear from it again and then five years later you get an email with this in it. Oh, just me then.

In this instance it was a fix for Excel 2010 and I thought it was not used that much anymore so I throw something together with no error handling. It was one of those; there you go, that is the last time ill hear from them. Anyway, I had to change the default font size of Excel after installation from 10.5 to 10. This was to fix an issue with the PowerPivot add-in. From Excel 2013, it’s built in now.

When I got the email I asked the person who reported the issue to click on the “view problem details” highlighted above. Guess what? It did not help so I have to write some diagnostics into the exe to output an error message. I then had to handhold the user to execute it. Here is the code, just two simple lines.

Microsoft.Office.Interop.Excel.Application _app = new Microsoft.Office.Interop.Excel.Application();
_app.StandardFontSize = 10;

There is not much to go wrong but we had this error.

Hmmm. Luckily I found this Microsoft support article.

It turns out that all our Excel deployments that use Powerpivot were installed on machines configured for en-US locale. Suddenly it was installed on a machine configured for en-PL, a Polish locale. The Excel installation was not a Polish version but the US English version.

Luckily the fix turned out to be very simple. Just set the current thread to en-US before instantiating the Excel object.

Thread.CurrentThread.CurrentCulture = new CultureInfo(“en-US”); 
Microsoft.Office.Interop.Excel.Application _app = new Microsoft.Office.Interop.Excel.Application(); 
_app.StandardFontSize = 10;


I doubt if I would have considered this however; you are only as good as your last failure. Don’t just throw anything over the fence at least without capturing errors..