7

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?

calico-cat
  • 1,324
  • 6
  • 20
  • 36
  • 1
    remove the reference (and anything that looks like it might be an excel reference) and re-add it – BlackICE Sep 01 '10 at 04:17
  • I can't mark this comment as the answer... :-p answer the question and I will. I removed the reference and it worked. – calico-cat Sep 01 '10 at 23:59

7 Answers7

6

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
Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
5

Removing and re-adding the reference solved this issue.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
calico-cat
  • 1,324
  • 6
  • 20
  • 36
  • 1
    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\"). – Peter Mortensen Jul 20 '15 at 20:15
1

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

J.Harrison
  • 11
  • 3
  • This helped me realise the problem was a duplicate Reference, but I had a different resolution: Drop down the 'References' in the Solution Explorer and just remove the unwanted duplicate. – TesseractE Apr 28 '17 at 14:46
0

I noted that the problems occur when you have two similar references, each in different locations. Thus the program is unable to narrow down to the one you are implying within the code.

Simply go to the properties page and remove one of them, and you should be fine.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tom K
  • 11
  • 4
0

I was having a similar issue picking up a project someone else had began (and was working for them), and it turns out that Visual Studio 2010 will consider the Microsoft Excel 15.0 Object Library to be a different reference than the Microsoft.Office.Interop.Excel.dll specifically. In my project, I had to remove the Microsoft.Office.Interop.Excel.dll and keep the Excel 15.0 Object Library for it to work.

sk8forether
  • 247
  • 2
  • 9
0

Create a new project and copy all those lines of commands from your old project and then go ADD REFERENCE and select anew the MS interop.

tuomastik
  • 4,559
  • 5
  • 36
  • 48
0

Run the NuGet package manager update for Microsoft.Office.Interop.Excel. After that, all my problems went away!

Andrew
  • 51
  • 2