BUG: "Old format or invalid type library" error when automating Excel (320369)
The information in this article applies to:
- Microsoft Office Excel 2003
- Microsoft Excel 2002
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# .NET (2002)
- Microsoft Visual C# .NET (2003)
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual C++
- Microsoft Visual J# .NET 2002
- Microsoft Visual J# .NET (2003)
- Microsoft Visual Studio Tools for the Microsoft Office System version 2003
This article was previously published under Q320369 SYMPTOMS If you automate Microsoft Excel with Microsoft Visual Basic
.NET, Microsoft Visual C# .NET, or Microsoft Visual C++, you may receive the
following error when calling certain methods: Error: 0x80028018 (-2147647512) Description: Old Format
or Invalid Type Library CAUSE You receive this error calling an Excel method when the
following are true:
- The method requires an LCID (locale identifier).
- You run an English version of Excel but the regional
settings for the computer are configured for a non-English language.
If the client computer runs the English version of Microsoft
Excel and the locale for the current user is configured for a language other
than English, Excel will try to locate the language pack for the configured
language. If the language pack is not found, the error is reported.
WORKAROUND To work around this problem, you can:
- Install the Multilingual User Interface Pack for your
version of Office.
- Or, execute the Excel method or property using InvokeMember so that you can specify the CultureInfo for the call. For example, the following code illustrates how you
can invoke the Workbooks object Add method with "en-US" as the CultureInfo:
Dim oApp As New Excel.Application()
oApp.Visible = True
oApp.UserControl = True
Dim oBooks As Object = oApp.Workbooks
Dim ci As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("en-US")
oBooks.GetType().InvokeMember("Add", Reflection.BindingFlags.InvokeMethod, Nothing, oBooks, Nothing, ci)
- Or, set the CultureInfo prior to calling the Excel method. For example:
Dim oApp As New Excel.Application()
oApp.Visible = True
oApp.UserControl = True
Dim oldCI As System.Globalization.CultureInfo = _
System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = _
New System.Globalization.CultureInfo("en-US")
oApp.Workbooks.Add()
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI
When you use one of these workarounds for a computer where
the regional settings do not match the current language version of Office, you
should be familiar with how Excel behaves and how Excel will interpret data
that might be formatted for a specific locale. For more details about writing
globalized Excel solutions with Visual Studio .NET, please see the following
articles in the MSDN: Creating Office Solutions for Use in Multiple
Countries/Regions http://msdn.microsoft.com/library/en-us/odc_vsto2003_ta/html/odc_VSTMultCR.aspGlobalization
and Localization Issues for Solutions Created with Microsoft Visual Studio
Tools for the Microsoft Office System http://msdn.microsoft.com/library/en-us/odc_vsto2003_ta/html/VSTO_globalization.aspSTATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed at the beginning of this article.
REFERENCES For more information on Office Automation, visit the
following Microsoft Office Development Web site: For information about the Office XP Multilingual User
Interface Pack, see: Availability of Office XP with Multilingual User
Interface Pack http://www.microsoft.com/office/evaluation/indepth/multilingual/muipackavailable.asp
Additionally, see the following Microsoft Knowledge Base articles:
301982 HOWTO: Automate Microsoft Excel from Visual Basic .NET
302084 HOWTO: Automate Microsoft Excel from Visual C# .NET
Modification Type: | Minor | Last Reviewed: | 2/3/2006 |
---|
Keywords: | kbvs2002sp1sweep kbAutomation kbbug kbpending KB320369 |
---|
|