Visual Studio Tools for Office Startup Query

Just starting with this technology, got a book and entered the first program:

using System;

using Excel = Microsoft.Office.Interop.Excel;

using System.Windows.Forms;

namespace ConsoleApplication

{

class Program

{

static bool exit = false;

static void Main(string[] args)

{

Excel.Application myExcelApp = new Excel.Application();

myExcelApp.Visible = true;

myExcelApp.StatusBar = "Hello World";

myExcelApp.Workbooks.Add(System.Type.Missing);

myExcelApp.SheetBeforeDoubleClick +=

new Excel.AppEvents_SheetBeforeDoubleClickEventHandler(myExcelApp_SheetBeforeDoubleClick);

while (exit == false)

System.Windows.Forms.Application.DoEvents();

}

static void myExcelApp_SheetBeforeDoubleClick(object sheet, Excel.Range target, ref bool cancel)

{

exit = true;

}

}

}

Problem is on the first couple of lines, my errors are:

Error 1 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference ) C:\Documents and Settings\mark\My Documents\Visual Studio 2005\Projects\AutomationOfExcel\AutomationOfExcel\Program.cs 3 14 AutomationOfExcel

Error 2 The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference ) C:\Documents and Settings\mark\My Documents\Visual Studio 2005\Projects\AutomationOfExcel\AutomationOfExcel\Program.cs 2 25 AutomationOfExcel

I have installed the PIA's under Office 2003 and wonder why 'Windows' & 'Office' seem to be unknown by VS2005



Answer this question

Visual Studio Tools for Office Startup Query

  • User77

    Hi Rawky76,

    Thanks for your reply!
    The Excel reference should be in the COM Tab.
    I feel strange that you have no COM Tab, in the Add Reference Dialog.
    If that is true, I think you have to reinstall your IDE to refresh the non-complete installation.

    If you still have any concern, please feel free to post here.

    Best regards,
    Peter Huang



  • MichaelEaton

    Thanks! I remember reading something about that now! I'll check back over previous pages. Thanks again!


  • vpsdhillon

    Hi,

    You need to add reference to two dll in the add reference dialog by right clicking on the project and select "Add reference"
    1. Add Reference to the System.Windows.Forms dll
    2. Add Reference to Microsoft Excel 11.0 Object Library

    302084 How to automate Microsoft Excel from Microsoft Visual C# .NET
    http://support.microsoft.com/default.aspx scid=kb;EN-US;302084

    If I misunderstood, please feel free let me know.

    If you still have any concern, please feel free to post here.

    Best regards,
    Peter Huang



  • RobMiles

    Ok, I've managed to Add Reference to the System.Windows.Forms dll but there is no Excel listed!

    In the book there is a COM tab on the Add Reference dialogue but I dont have a COM tab I have installed the PIA's I'm sure, so what's missing


  • Visual Studio Tools for Office Startup Query