I have an application that opens up Excel, reads some information, then closes Excel. I developed this application using Microsoft Office XP 2007. A few weeks ago, my company upgraded to Microsoft Office 2010. The applications still works fine, but I can not compile in VS 2008 anymore. I get the error message: "Error 3 'Application' is ambiguous in the namespace 'Microsoft.Office.Interop.Excel'." I have updated my COM reference to Microsoft Office 14.0 Object Library, but the same message appears. Here is some code I have used:

Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel

Public Class frmImportDoc
    Dim trFile As New Excel.Application   '<---- Application is 'Ambiguous' in the namespace
    Dim trSheet As New Excel.Worksheet    '<---- Application is 'Ambiguous' in the namespace

    Private Sub btnImportDoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImportDoc.Click
        'open file window for user to select document
        OpenFileDialog1.ShowDialog()
        Dim intResult As Integer
        strFilename = OpenFileDialog1.FileName
        If strFilename = "" Then
            Exit Sub
        Else
            'open the excel sheet selected by user
            trFile.Workbooks.Open(Me.strFilename)

Obviously there is a bunch of stuff under this, but this shows where the errors are.

I am unable to fix a bug in the program because I can not even compile it without error. Any help is much appreciated! Thanks!

Try this:

Imports Excel = Microsoft.Office.Interop.Excel

Public Class frmImportDoc
    Dim trFile As Excel.Application
    ....

Or you can try removing and re-adding the reference.
Or you can simply ignore the Imports altogether and use the full name in the code.

I tried the code you posted, but the same thing happens. For the sake of testing, I tried using the full name and get a mess of other errors. I have removed and added references and tried compiling between actions but still, nothing works.

This is actually getting sort of frustrating. Personally, I don't like the new Office 2010, and this is just decorating the cake for me.

I appreciate your help. Thanks!

I found some more information regarding the removal and re-adding of the reference method I posted.

After you remove the reference from the project, you should also delete the auto-generated Excel interop assembly in the application's bin folder.
Then re-add the reference to the project.

i found that removing the refereence all together and my solution works with just the imports command. perhaps this version of VS does not need both reference and imports? it seems to be adding it twice when its in the reference and also has an imports. i did not try to use reference without imports

If you remove your 'Microsoft reference'(old or current reference) by Go> Project>Property>References*>Select "Microsoft Office xx Object Library" or/and Microsoft Excel xx Object Library" or/and Microsoft Word xx Object Library" > Click 'remove' button.** Hope your error/problem will be solved. I found that removing the all Microsoft reference and my solution works with just the imports command. No Microsoft.Office.Interop.Excel or word or outlook problem in any office.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.