Help and Support
 

powered byLive Search

BUG: "Old format or invalid type library" error when automating Excel

Article ID:320369
Last Review:May 11, 2007
Revision:8.4
This article was previously published under Q320369
On This Page

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

Back to the top

CAUSE

You receive this error calling an Excel method when the following conditions are true:
The method requires an LCID (locale identifier).
You run an English version of Excel. However, the regional settings for the computer are configured for a non-English language.
If the client computer runs the English version of 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.

Back to the top

WORKAROUND

To work around this problem, you can use one of the following methods:
Install the Multilingual User Interface Pack for your version of Office.
Execute the Excel method or property by 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://msdn2.microsoft.com/en-us/library/aa168494(office.11).aspx (http://msdn2.microsoft.com/en-us/library/aa168494(office.11).aspx)
Globalization and Localization Issues for Solutions Created with Microsoft Visual Studio Tools for the Microsoft Office System
http://msdn2.microsoft.com/en-us/library/aa192494(office.11).aspx (http://msdn2.microsoft.com/en-us/library/aa192494(office.11).aspx)

Back to the top

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

Back to the top

MORE INFORMATION

Steps to reproduce the behavior

1.Verify that the locale for the computer is set to a language other than English.

For Windows 2000:
a. In Windows Control Panel, double-click Regional Options.
b. On the General tab, select a location, and then click OK.
For Windows XP or Windows Server 2003:
a. In Control Panel, open Regional and Language Options.
b. On the Regional Options tab, select a locale, and then click OK.
2.Start Microsoft Visual Studio .NET.
3.On the File menu, point to New, and then click Project. In the New Project dialog box, under Project Types, click Visual Basic Projects. Under Templates, click Windows Application, and then click OK. By default, Form1 is created.
4.On the View menu, click Toolbox, and then add a button to Form1.
5.To display the code window for the form, double-click Button1.
6.In the code window, replace the following code
Private Sub Button1_Click(ByVal sender As System.Object, _
                          ByVal e As System.EventArgs) _
                          Handles Button1.Click
End Sub
					
with:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim oApp As Object
    Dim oDoc As Object
    oApp = CreateObject("Excel.Application")
    oApp.Visible = True
    oDoc = oApp.Workbooks.Add
    oDoc.Close()
    oApp.Quit()
    oDoc = Nothing
    oApp = Nothing
End Sub
					
7.Add the following line to the beginning of the Form1 code module:
Option Strict Off
8.Press F5 to build and run the program.
9.To generate the error, click Button1. The error occurs on the line that reads:
oDoc = oApp.Workbooks.Add
					

Back to the top

REFERENCES

For more information on Office Automation, visit the following Microsoft Office Development Web site:
http://support.microsoft.com/ofd (http://support.microsoft.com/ofd)
Additionally, see the following Microsoft Knowledge Base articles:
301982 (http://support.microsoft.com/kb/301982/) How to automate Microsoft Excel from Visual Basic .NET
302084 (http://support.microsoft.com/kb/302084/) How to automate Microsoft Excel from Microsoft Visual C# .NET

Back to the top


APPLIES TO
Microsoft Office Excel 2007
Microsoft Office Excel 2003
Microsoft Excel 2002 Standard Edition
Microsoft Visual Basic .NET 2002 Standard Edition
Microsoft Visual C# .NET 2002 Standard Edition
Microsoft Visual C# .NET 2003 Standard Edition
Microsoft Visual C# 2005
Microsoft Visual Basic .NET 2003 Standard Edition
Microsoft Visual C++ 6.1
Microsoft Visual J# .NET 2003 Standard Edition
Microsoft Visual Studio Tools for the Microsoft Office System version 2003

Back to the top

Keywords: 
kbvs2002sp1sweep kbautomation kbbug kbpending KB320369

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.