Saturday, April 20, 2024 :: Login  

Excel LCID or Locale issue - HRESULT: 0x800A03EC / Old format or invalid type library

 

What is the Excel Locale/LCID issue?  If you automate Microsoft Excel with Microsoft Visual Basic .NET, Microsoft Visual C# .NET, or Microsoft Visual C++, you may receive the following errors when calling certain methods because the machine has the locale set to something other than US English (locale ID or LCID 1033):

Exception from HRESULT: 0x800A03EC
 

and/or

Old format or invalid type library

SOLUTION 1:

To get around this error you can set CurrentCulture to en-US when executing code related to Excel and reset back to your originale by using these 2 functions.

C#
 

//declare a variable to hold the CurrentCulture
System.Globalization.CultureInfo oldCI;
//get the old CurrenCulture and set the new, en-US
void SetNewCurrentCulture()
{
  oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
  System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
}
//reset Current Culture back to the originale
void ResetCurrentCulture()
{
  System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
}



VB
 

'declare a variable to hold the CurrentCulture
Dim oldCI As System.Globalization.CultureInfo
'get the old CurrenCulture and set the new, en-US
Private Sub SetNewCurrentCulture()
  oldCI = System.Threading.Thread.CurrentThread.CurrentCulture
  System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
End Sub
'reset Current Culture back to the originale
Private Sub ResetCurrentCulture()
  System.Threading.Thread.CurrentThread.CurrentCulture = oldCI
End Sub


Something like this:

C#

 

void dosomeexcelstuf()
  {
    SetNewCurrentCulture();
    Excel.Application ExcelApp = new Excel.Application();
    Excel.Workbooks ExcelBooks = (Excel.Workbooks)ExcelApp.Workbooks;

      //....... 
       try
        {
           //......... 
         }catch (Exception ex)
            {
             //............................ 
            }
            finally
            {
                ExcelBooks.Close();
                ExcelApp.Quit();
                ResetCurrentCulture();
            }

}


VB

 

 SetNewCurrentCulture() Dim ExcelApp As New Excel.Application() Dim ExcelBooks As Excel.Workbooks = DirectCast(ExcelApp.Workbooks, Excel.Workbooks) '....... '......... Try '............................ Catch ex As Exception Finally ExcelBooks.Close() ExcelApp.Quit() ResetCurrentCulture() End Try

 

http://support.microsoft.com/kb/320369/en-us


SOLUTION 2:

Another solution that could work, create a 1033 directory under Microsoft Office\Office11 (or your corresponding office-version), copy excel.exe to the 1033 directory, and rename it to xllex.dll.

Although you might solve the problem using one off these solutions, when you call the Excel object model in locales other than US English, the Excel object model can act differently and your code can fail in ways you may not have thought of.  For example, you might have code that sets the value of a range to a date:

yourRange.Value2 = "10/10/09"

Depending on the locale this code can act differently resulting in Excel putting into the range any of the following values:

October 10, 2009
September 10, 2009
October 9, 2010

Other code you write can be affected as well--you might have code that sets or checks for a formula using the "Sum()" function but this will break in different locales because the Sum function might be localized to some other string like "Summe()"

Privacy Policy www.made4dotnet.com 2020

Map IP Address
Powered byIP2Location.com

   Terms Of Use   ::   Privacy Statement   ::   Copyright (c) 2024 www.made4dotnet.com - .NET Development