I'm getting the error "Application" is ambiguous in the namespace 'microsoft.office.interop.excel'

25,984

Solution 1

Removing and re-adding the reference solved this issue.

Solution 2

I don't think you should have the line as Imports Microsoft.Office.Interop. Either use

Imports Excel = Microsoft.Office.Interop.Excel

And then use it as:

Dim xl As Excel.Application

Or remove the Imports all together and use the full name everywhere, as:

Dim xl As Microsoft.Office.Interop.Excel.Application

Solution 3

Experienced the same problem and was able to identify the issue and resolve (note: my issue was with Outlook but same error occurred when using Excel):

  1. Go to Project >> Add References >> Assemblies >> (search Outlook) and UNCHECK ALL Microsoft.Office.Interop.Outlook that are checked (I had version 14 checked).
  2. Go to Project >> Add References >> COM >> (search Outlook) >> CHECK Microsoft Outlook xx Object Library

After doing this the code "Dim olObject as Outlook.Application" no longer had the 'Application' is ambiguous in the namespace 'Microsoft.Office.Interop.Outlook.

The same method worked to resolve Excel

Share:
25,984

Related videos on Youtube

calico-cat
Author by

calico-cat

I have many interests - software development is one of them!

Updated on November 05, 2020

Comments

  • calico-cat
    calico-cat over 3 years

    I have a project which opens a simple Excel file and populates it. It was working fine until this morning, when it has suddenly started giving me the error above: 'Application' is ambiguous in the namespace 'Microsoft.Office.Interop.Excel'.

    I haven't changed any project references, or anything within the file itself. The references include Microsoft.Office.Interop.Excel. The imports statement is there: imports Microsoft.Office.Interop

    The object declaration is also complete: Dim xl As Microsoft.Office.Interop.Excel.Application which is the line that's giving me the error!

    I've tried googling this error, and the only response is that I need to declare xl as Microsoft.Office.Interop.Excel.Application.

    The fact that I hadn't changed anything within the project nor the code tells me this is a corruption in Visual Studio 2008. However, cleaning and rebuilding the project, rebooting Windows, and restarting VS has no effect.

    Any ideas?

    • BlackICE
      BlackICE over 13 years
      remove the reference (and anything that looks like it might be an excel reference) and re-add it
  • Peter Mortensen
    Peter Mortensen almost 9 years
    Thanks for that solution. That worked for me too for a different component, tvc.ocx from Tektronix (installed with TekVISA v. 4.04). I got the same error as I moved a Visual Studio project to another computer with the exact same version of the Tektronix software. Removing the references and adding them back in (adding tvc.ocx from "C:\Program Files\IVI Foundation\WinNT\TekVISA\Bin\" to the toolbox and dragging "Tvc Control" to the main form. And adding Ivi.Visa.Interop.dll from "C:\Program Files\IVI Foundation\VISA\VisaCom\Primary Interop Assemblies\").