Solved

vb.net Office Excel Interop Assembly Fails

Posted on 2010-09-21
9
1,281 Views
Last Modified: 2013-11-26
I get the following error when trying to export my dataset to excel.  

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)).

Apparently the interop assemblies are not registered.  Failure occurs on the 'excelApp.Workbooks.Add" is executed.  I have added the reverence to Microsoft.Office.Interop.Excel (Version 12.0.0.0).  I have Office 2007 on my PC.  I have used this exact code in the past and it worked fine.  Do I need to register the asseblies again?  If so, how.  I have already repaired Office 2007 and that did not work.  I'm running Visual Studio 2008 with.net framework of 3.5

Thanks for the help.
Select Case TC_ServiceData.SelectedIndex
            Case Is = 1
                Me.Cursor = Cursors.WaitCursor
                Dim excelApp As New Microsoft.Office.Interop.Excel.Application()
                Dim excelBook As Microsoft.Office.Interop.Excel.Workbook = excelApp.Workbooks.Add
                Dim excelWorksheet As Microsoft.Office.Interop.Excel.Worksheet = _
                    CType(excelBook.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet)
                excelApp.Visible = False

                With excelWorksheet
                    'Creates connections to pull data to DataSet

                    Dim dr As DataRow
                    Dim i As Integer = 2
                    .Range("A1").Value = "TECHNICIAN"
                    .Range("A1").Font.Bold = True
                    .Range("A1").ColumnWidth = 15
                    .Range("B1").Value = "CALL DAY"
                    .Range("B1").Font.Bold = True
                    .Range("B1").ColumnWidth = 15
                    .Range("C1").Value = "TIME"
                    .Range("C1").Font.Bold = True
                    .Range("C1").ColumnWidth = 15
                    .Range("C1").Value = "STATUS"
                    .Range("C1").Font.Bold = True
                    .Range("C1").ColumnWidth = 15
                    .Range("C1").Value = "CALL NUMBER"
                    .Range("C1").Font.Bold = True
                    .Range("C1").ColumnWidth = 15
                    .Range("C1").Value = "CUSTOMER"
                    .Range("C1").Font.Bold = True
                    .Range("C1").ColumnWidth = 50

                    'Populate Excel spreadsheet
                    Try
                        For Each dr In mDataSet.Tables(0).Rows

                            .Range("A" & i.ToString).Value = dr("controlId")
                            .Range("B" & i.ToString).Value = dr("orderId")
                            .Range("C" & i.ToString).Value = dr("pickupDate")
                            i += 1


                        Next
                    Catch ex As Exception
                        Me.Cursor = Cursors.Default
                        MessageBox.Show(ex.Message)
                    End Try
                    'Make Excel visible
                    excelApp.Visible = True
                    Me.Cursor = Cursors.Default
                End With
                Me.Cursor = Cursors.Default
            Case Is = 1


        End Select

Open in new window

0
Comment
Question by:toddpotter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 33726801
0
 

Author Comment

by:toddpotter
ID: 33727215
No. That didn't get me anywhere.
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 33727256
Hmmmm! OK.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 6

Expert Comment

by:xenacode
ID: 33732381
Office is just a bit temperamental like that sometimes.

Try declaring excelApp as Microsoft.Office.Interop.Excel._Application (note the underscore). This sometimes works for similar issues.

It does sound like a PIA issue may be the cause. Have you got more than one version of the PIA installed?

Pete
Xenacode Ltd
0
 

Author Comment

by:toddpotter
ID: 33733360
Using the underscore did not work.

I have attached two screenshots - one of the assembly folder and one of my program list.  I have MS Office 2007 installed (with every option) and a seperate Microsoft Office 2007 Interop Assemblies.  I removed the 'Microsoft Office 2007 Interop Assemblies" yesterday and repaired office 2007 thinking there may be a conflict but it had the same results.  


assembly.PNG
programs.PNG
0
 
LVL 6

Expert Comment

by:xenacode
ID: 33733536
have you got anything in the GAC with a name like "Policy.12.0.Microsoft.Office.Interop.Excel"?
0
 

Author Comment

by:toddpotter
ID: 33733587
Yes Policy.11.0.Microsoft.Office.Interop.Excel
assembly2.PNG
0
 
LVL 6

Accepted Solution

by:
xenacode earned 500 total points
ID: 33733884
That one is OK but you also have a Policy.12.0.Office version 14 in your GAC that suggests someone has installed (part of) Office 2010. I'm guessing but that might be something to do with it. What that means is that any calls from an application to the Office 2007 PIA get redirected to the Office 2010 PIA. I can't confirm if that would give you this problem or not but, from my experience, VSTO add-ins can get really messed up when you have components from multiple Office versions installed simultaneously.
0
 

Author Comment

by:toddpotter
ID: 33734819
I had a copy of Microsoft Project Beta 2010 on my machine.  Once I uninstalled it, the app no longer errors on the excelapp.Workbooks.Add but when it catches a breakpoint VS hands and comes back with an error of:
---------------------------
Microsoft Visual Studio
---------------------------
A fatal error has occurred and debugging needs to be terminated. For more details, please see the Microsoft Help and Support web site. HRESULT=0x80131c08. ErrorCode=0x0.
---------------------------
OK  
---------------------------
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question