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

Posted on 2006-04-20
Last Modified: 2010-02-25

I am using Microsoft Visual Studio.NET 2003. I am trying to do somw work with EXCEL and keep getting the following error.

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

I have added the following to the project:

Microsoft Excel 11.0 Object Library
Microsoft Office 11.0 Object Library
Microsoft XP PIA's

the following is my code but it doesn't seem to recognise        using Excel;
Wwould appreciate any help.

using System;
using Excel;
using System.Collections;

namespace exer
      class ExcelClass
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            private string Cfilename;
            public    Excel.Application excelApp ; // Creates a new Excel Application
            public Excel.Workbook excelWorkbook;
            public Excel.Sheets excelSheets;
            public Excel.Worksheet excelWorksheet;

            public void Start(string filename)
                  excelApp = new Excel.ApplicationClass();
                  excelWorkbook = excelApp.Workbooks.Open(filename, 0,
                        false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true,
                        false,  0, true, false, false);
            public void openSheet(string currentSheet)           // The following gets the Worksheets collection
                  excelSheets = excelWorkbook.Worksheets;
                  excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
            public void setcell(string val)
                  // The following gets cell A1 for editing
                  excelSheets = excelWorkbook.Worksheets;
                  Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("A1", "A1");

                  // The following sets cell A1's value to "Hi There"
                  excelCell.Value2 = val;
            public void view()
                  excelApp.Visible=true;// Makes Excel visible to the user.
            public void Close()


Question by:gmoconno
    LVL 6

    Accepted Solution

     using Excel = Microsoft.Office.Interop.Excel;

    Author Comment

    Thanks alot e1v. No more errors. A bit new to this thing.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    This video discusses moving either the default database or any database to a new volume.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now