Create .NET Components for Excel
If you are an experienced VBA programmer, this is a great way to start learning .NET because you can take advantage of features built into the .NET Framework in small, incremental steps.
To create a .NET component for use in Excel:
From within Visual Studio .NET , create a new class library project using Visual Basic .NET or C#. Visual Studio creates a folder and template files for the project, as shown in Figure 25-1.
Figure 25-1. A new, empty .NET class library project
From the Project menu, choose Add Class. Visual Studio displays the Add New Item dialog box shown in Figure 25-2.
Give the new class a descriptive name and click OK. Visual Studio registers the project to interoperate with COM (the Register for COM Interop selection on the Project Options, Build dialog box) and creates a new, empty code template for your class as shown in Figure 25-3.
Add code to the class library for the objects, properties, and methods you want to use from Excel.
Compile the project by selecting Build Solution from the Build menu. Visual Studio builds the class library as a .NET assembly (.dll) and creates a type library file (.tlb) that allows Excel and other COM applications to use that assembly. Both of these files are placed in a \bin folder within the project folder created in Step 1.
For example, the NetForExcel project (NetForExcel.sln) includes a simple class ...
Get Programming Excel with VBA and .NET 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.