Use Excel as a Component in .NET
Another way for Excel to interact with the .NET world is to program with Excel objects directly in VB.NET. In this case, Excel becomes a component for use in a .NET application—the reverse of the case just shown.
Using Excel as a component in a .NET application is handy when you want to present application output using the Excel interface—as a spreadsheet or chart, for instance.
Excel works as a component, too. It’s a big one, though, and you need to be carefulwhen using it from .NET applications.
How to do it
To create a .NET application that uses Excel as a component:
Create a new Windows application project in Visual Studio .NET.
Choose Project → Add Reference. Visual Studio .NET displays the Add Reference dialog box, click the COM tab. Visual Studio .NET displays the COM objects registered on your system as shown in Figure 5-10.
Figure 5-10. Adding a reference to the Microsoft Excel object library
Select the Microsoft Excel 11.0 Object Library and click Select, then OK to add the reference to your project. Visual Studio .NET automatically references the PIA for the Excel object library if it is installed on your system.
If the PIA is not installed, Visual Studio .NET creates a new interop assembly and adds it to your project (this is not what you want—the PIA is much more reliable). To make sure you are using the PIA, check the Name ...