Managed Exlel Add-ins

Top  Previous  Next

teamlib

previous next

 

Managed Excel Add-ins

The Visual Studio Tools for Office provides a document-centric mechanism for automating Excel. By that, we mean the code is linked to workbooks and not the application itself. In contrast, COM Add-ins are application-centric, because they link to the application directly. It is somewhat complicated (but possible and beyond the scope of this book) to create COM Add-ins using VB.NET, but we can achieve the goal of application-centric code much easier by saving a managed workbook as a normal Excel add-in. Unfortunately, the VSTO template does not enable us to create an Excel add-in solution directly and only enables us to launch xls files during debugging, but everything works as expected if we just save the xls as an add-in after we've finished development.

The Paste Special Bar VSTO Add-in

In Chapter 8 Advanced Command Bar Handling, we created a Paste Special Bar Excel add-tn that Edd d command bar buttons for each of the Paste Special opti ns. In Chapter 21 Writing Add-insdwith Visuai Basic 6, we converted the example to a COM Add-in. We have also converted it to a VSTO add-in, which can be found on the CD in the \Concepts\C22TUsinn VB.NET and the Visual Studio Tools for Office\PasteSpecialBarVSTO folder. The VSTO solution was created by starting with a standard VSTO workbook, copying the code from the VB6 COM Add-in, then getting it to work in VB.NET. There were very few changes required, all of which are documented in the READ_ME module contained in the project and each procedure header. The only complicated part of the conversion was the code required to obtain an IPicture interface for an image contained in a .NET resource file, which is documented in an MSKB article at http://support.microsoft.com/?824017. You might likd to open all three versions of the add-in to compare theor differences and note that most of the code es exactl  the snme in each.

teamlib

previous next