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?
Can you try this... using Excel = Microsoft.Office.Interop.Excel; (as found from here)
Try changing your
using
to:That way
Excel
will be an alias for the full namespace, which the rest of the code seems to expect.