VSTO “Old format or invalid type library” when automating Excel

I am working on a project that automates Excel and is used in countries around the world.  One of the hurdles we have faced was encountering this beauty of an error:

Error: 0x80028018 (-2147647512)
Description: Old Format or Invalid Type  Library

I imagine that it might be quite the lovely error message for some, but for us it was a bit of a pain in the arse.

You have a few options when dealing with this error. You can set the current thread to English explicitly before calling Excel methods. This allows you force the 1033 language code on the interop which works fine.

What if you have legacy code? Or maybe you don’t want to change your code in every place that calls Excel to change the thread culture. Maybe you actually want your threads to respect the current culture because your not a lame VBA programmer who only knows how to program for English.

So, I worked with the other solution. Make a folder in the Excel folder with the LCID of 1033 and one for the LCID of the CURRENT region set in Windows.

NOTE: DO NOT OVERWRITE ANY FILES IF THEY ALREADY EXIST, YOU WILL NOT BE HAPPY!

Copy the Excel.EXE to the that folder and rename it to XLLEX.DLL.

Voila! You are done.

I wrote an application that does all this automatically for you that is easy to use. If there is any interest, I will post it up here.  I don’t feel like wasting my time though if no one cares.

If you want to read the kb, click here.

Happy Coding!

0 Replies to “VSTO “Old format or invalid type library” when automating Excel”

Leave a Reply

Your email address will not be published. Required fields are marked *