Section 5.1.Work with .NET


5.1. Work with .NET

There are three main approaches to using .NET with Excel. You can use .NET to create:

  • Components that can be used from Excel macros. This approach works with all Excel versions and is much the same as creating COM components for use with Excel using Visual Basic 6.0. The .NET tools automatically generate the type libraries needed to use .NET objects from COM applications such as Excel.


    Note: Code used in this chapter and additional samples are available in ch05. xls.
  • Standalone applications that use Excel as a component. This approach works best with Excel XP and 2003, since those versions provide the files needed to use Excel from .NET applications smoothly. In this scenario, the user starts a stand-alone application to create or modify Excel workbooks.

  • Workbook-based applications that run all of their code as .NET. This approach works for Excel 2003 only. In this scenario, the user opens the workbook which automatically loads the .NET assembly containing the application code. The workbook contains a link to this assembly, so the workbook file (.xls) can be distributed to many different users and locations, while the assembly (.dll) resides in a single location (for example at a network address).


Note: .NET isn't important just because it's new. It is much more consistent than VBA, includes a lot of great builtin classes, has a more complete security model, and supports inheritance. There's a lot to digest, so lets get started!

5.1.1. What you need

From the user's standpoint, the main differences between these approaches are how you start the application and what versions of Excel are supported. From a developer's standpoint, the differences affect how you develop, debug, and deploy the applications. Even the development tools you need vary somewhat between these approaches as described in Table 5-1.

Table 5-1. Software requirements for developing between Excel and .NET
To createYou need
.NET components for use in ExcelVisual Studio .NET standard edition or higher.
Standalone .NET applications that use Excel

Visual Studio .NET standard edition or higher
Microsoft Office XP or 2003 Primary Interop Assemblies (PIAs).

Excel .NET ApplicationsVisual Studio .NET Tools for Office (includes above plus project templates)


5.1.2. Where to get it

To getLook here
Visual Studio .NET editions msdn.microsoft.com/vstudio/howtobuy/
Office XP PIAsSearch www.microsoft.com/downloads for "Office XP PIAs"
Office 2003 PIAsInstall Professional Edition with the .NET programmability option selected for each application.
Visual Studio .NET Tools for Office msdn.microsoft.com/vstudio/howtobuy/officetools/




    Excel 2003 Programming. A Developer's Notebook
    Excel 2003 Programming: A Developers Notebook (Developers Notebook)
    ISBN: 0596007671
    EAN: 2147483647
    Year: 2004
    Pages: 133
    Authors: Jeff Webb

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net