O'Reilly logo

Programming Excel with VBA and .NET by Steve Saunders, Jeff Webb

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Create Excel Applications in .NET

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.

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.

When Visual Studio .NET creates an Excel project, it adds references to the Microsoft ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required