Create Excel .NET Applications

A third and final way for Excel and .NET to interact is through the Visual Studio .NET Tools for Office. This set of tools includes Visual Studio .NET project templates for Excel and Word. These project templates allow you to link a specific document to a .NET assembly that loads whenever the user opens that document. The .NET code in the assembly can control Excel and respond to Excel events as described in the preceding sections.

How to do it

To create an Excel application in Visual Studio .NET:

  1. From the Project menu, choose New, Project. Visual Studio .NET displays the New Project dialog box.

  2. Select the Microsoft Office System Projects, Visual Basic Projects project type and Excel Workbook template, give the project a descriptive name and click OK. Visual Studio .NET starts the Microsoft Office Project Wizard to walk you through.

  3. Click Finish to create the project folder and empty workbook and code template files.

  4. Visual Studio .NET doesn’t automatically add the workbook to the project, so it is a good idea to add it at this point. From the Project menu, choose Add Existing Item and then select the .xls file found in the application folder.

  5. Once the workbook is added to the project, select the workbook in the Solution Explorer and set its Build Action property to Content. This will ensure that the workbook is distributed with your application if you create an installation program.

How it works

When Visual Studio .NET creates ...

Get Excel 2003 Programming: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.