• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2373
  • Last Modified:

Problem creating Excel file from VB.NET; Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).

I want to create excel worksheet from my VB.NET Project. I have searched & tried a code from web. I am developing in Visual studio 2008, using excel 2007, and added the nessasory referances to my project. The code does not show any error However, when executed, at the point of creating the workbook, runtime error occurs.

Error Message :
Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).

what does this error mean and what is cure for it ?
Imports Excel = Microsoft.Office.Interop.Excel

Public Class ExcelTest
    Inherits System.Windows.Forms.Form

    Friend WithEvents Button1 As Button

    Public Sub New()

        Button1 = New Button
        With Button1
            .Location = CalcLocation(2, 10)
            .Size = CalcSize(1.5, 10)
            .Text = "TEST"
        End With

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet
        Dim misValue As Object = System.Reflection.Missing.Value

        xlApp = New Excel.ApplicationClass
        xlWorkBook = xlApp.Workbooks.Add(misValue)
        xlWorkSheet = CType(xlWorkBook.Sheets("sheet1"), Excel.Worksheet)
        xlWorkSheet.Cells(1, 1) = "http://vb.net-informations.com"



        MsgBox("Excel file created , you can find the file c:\")
    End Sub

    Private Sub releaseObject(ByVal obj As Object)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        End Try
    End Sub
End Class

Open in new window

  • 4
  • 3
2 Solutions
Verify that Excel is installed and version is not lower than that used to create the program.
kkp01Author Commented:
Thanks for your help. Verified the versions mis-match. Error was solved.
Now I used excel 2007 to create the program. Now the error disappeared. Previously I was using excel 2000, and XP files to create program.  
DOES THAT MEAN THAT : program created by using files of excel 2000/XP , will not work if client's computer is having latest version of excel ????
Yes, it has forward compatibility only.
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Sorry, in this case Forward compability must apply, but it is posible that broken on 2007 version.
kkp01Author Commented:
Thanks for your comments. ONE LAST CLEARIFICATION needed.
If I create program using excel 2000, and my clients are using office 2000, it is going to be ok. But if my clients upgrade to office 2007, then I will have to re-generate my program using excel 2007 files. BUT THEN WHAT HAPPENS to my other client who are not upgrading ?, are they forced to upgrade their office version ?.
WHAT is way out to provide a common program to office 2000 users and office 2007 users ? . Because I can not force all my clients to upgrade, Will I have to maintain different different versions of my program according to excel versions....
You can create two librarys, one for office 2000 and the other for 2007.
I do┬┤nt understand the borken fordward compatibility.
kkp01Author Commented:
I just want to make sure that if I am using office 2000 files to create my application which exports some data in excel sheet, and, such an application is running on a machine where office 2007 is installed.
All I want to know is that, in such situation, will my application be able to create an worksheet on that machine and export data ?

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now