Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 530
calico-cat Avatar asked Sep 01 '10 04:09

calico-cat


3 Answers

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
like image 198
Hans Olsson Avatar answered Sep 29 '22 03:09

Hans Olsson


Removing and re-adding the reference solved this issue.

like image 30
calico-cat Avatar answered Sep 29 '22 03:09

calico-cat


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

like image 27
J.Harrison Avatar answered Sep 26 '22 03:09

J.Harrison