Robert Niestroj
Robert Niestroj

Reputation: 16131

C# project does not see Excel COM Reference

im writing an application using Visual Studio 2010 Express Edition. I have a problem using Excel Automation. I added a COM Reference to Microsoft Excel 12.0 Object Library. It added following References:

Microsoft.Office.Core
Microsoft.Office.Interop.Excel 
VBIDE

I also added a using clause:

using Microsoft.Office.Interop.Excel;

Then i took a code snippet from microsoft:

m_objExcel = new Excel.Application();
m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
m_objBook = (Excel._Workbook)(m_objBooks.Add(m_objOpt));

and it underlines Excel and shouts:

The type or namespace name 'Excel' could not be found (are you missing a using directive or an assembly reference?)

I have Office 2007 Professional Plus and the "Interoperability component for .net 2.0 Microsoft Forms" (sorry, translation from polish) installed. Target Framework is .NET 4 Client Profile.

Any ideas what can be wrong?

Upvotes: 1

Views: 12207

Answers (2)

user368191
user368191

Reputation:

Can you try this... using Excel = Microsoft.Office.Interop.Excel; (as found from here)

Upvotes: 0

Hans Olsson
Hans Olsson

Reputation: 55009

Try changing your using to:

using Excel = Microsoft.Office.Interop.Excel;

That way Excel will be an alias for the full namespace, which the rest of the code seems to expect.

Upvotes: 11

Related Questions