|
5.12. Create Excel .NET ApplicationsA 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. 5.12.1. How to do itTo create an Excel application in Visual Studio .NET:
5.12.2. How it worksWhen Visual Studio .NET creates an Excel project, it adds references to the Microsoft Office and Excel 2003 PIAs, adds Imports statements to provide short cuts to the Office and Excel classes, and generates code to ThisApplication and ThisWorkbook objects as shown in Figure 5-15. Visual Studio .NET links the workbook to the project's assembly through two custom document properties: _AssemblyLocation0 and _AssemblyName0. The _AssemblyLocation0 property corresponds to the Visual Studio .NET project's Assembly Link Location property as shown in Figure 5-16. Figure 5-15. A newly created Excel project in Visual Studio .NETFigure 5-16. Setting Assembly Link Location changes the _AssemblyLocation0 custom document property in the Excel workbookYou might notice that an Excel project has both a \bin and a \ projectname _bin folder. Excel projects write assembly output first to the \bin folder, then copy that file to the secondary folder. This allows the project to compile even if the Excel workbook has the assembly open in the secondary folder, plus it allows the project to be automatically deployed to a public location every time you build ita process Microsoft calls no touch deployment . When you open an Excel workbook that has _AssemblyLocation0 and _AssemblyName0 custom properties, Excel automatically starts the Office Toolkit Loader addin (Otkloadr.dll). The Office Toolkit Loader addin then starts the .NET assembly specified in the AssemblyLocation0 and _AssemblyName0 properties. Tip: Visual Studio .NET Tools for Office are built for use with the .NET Framework, Version 1.1. Applications built with these tools work with later versions of the .NET Framework, but the security configuration and debugging portions of the tools do not. If you have a later version of .NET installed, you must set the .NET security policy for the project manually and attach the debugger to the process manually. 5.12.3. What about...
|
|