VSTO: My Favorite Feature(s)

As many readers may know, I’ve spent a lot of time over the past few years working with, writing about, and preaching the virtues of creating managed code that automates Office applications using Visual Studio Tools for Office, in its several versions. I believe this “Product That Could” has really reached critical mass, and with its pending release as an integral part of Visual Studio “Orcas”, developers will finally find a rich, powerful means of creating business applications that interact with the data that just about every single Windows user manipulates daily.

The current version, Visual Studio 2005 Tools for the 2007 Microsoft Office System (often called Visual Studio 2005 Tools for Office Second Edition, or just VSTO 2005 SE), is available, it’s powerful, and it’s free. If you’ve ever needed to create application-level customizations for Microsoft Word, Excel, PowerPoint, or Outlook, give this great product a look.

I’ve been asked by my old friend Mike Hernandez to list my “favorite feature” in VSTO, and it’s hard to do that—my actual favorite feature is that the product EXISTS. But moving past the obvious, I’d like to point out two features in the VSTO 2005 SE version that I use every single time I create applications using the product, and that you could easily miss.

  • The add-in template provides a Globals class, which allows access to the ThisAddIn class. Given this reference, you can programmatically interact with the host application at any point in your add-in, simply by referencing Globals.ThisAddIn.Application. When you’ve added a new class to the add-in, for example, it’s otherwise somewhat tricky to refer to the host application, and you’ll need to if you ever want to interact with Word, Excel, Outlook, and so on, from within the new class. Without this useful addition, you’d need to pass the Application reference from the add-in class around to all the other classes in the application.
  • VSTO 2005 SE makes it incredibly easy to add support for Ribbon customizations to your add-in. Other alternative techniques for adding Ribbon customizations to Word, Excel, PowerPoint, or Outlook involve ugliness that I wouldn’t impose on anyone. Doing the same with VSTO 2005 SE is elegant, and simply requires adding a new Ribbon Support item to the project. This action adds a partial class that handles loading the Ribbon customization, along with the Ribbon customization class itself. At runtime, the add-in executes a procedure that determines that the add-in has a Ribbon customization to supply, and loads it as it starts up. You just need to provide the RibbonX markup, and the callback procedures. (Yes, this process could be easier, and will be easier when VSTO “Orcas” ships, including a Ribbon designer. But that’s a topic for another day.) Given the current state of tools, I contend that VSTO 2005 SE provides the simplest and most elegant platform for adding Ribbon customizations to the applications that it supports.

For more “VSTO: My Favorite Feature” tips, visit the blog of product manager Mike Hernandez. You’ll find links to them all from there.

Published Tuesday, May 01, 2007 6:52 AM by KenG

Comments

Tuesday, May 29, 2007 7:58 AM by Abel DeSouza

# re: VSTO: My Favorite Feature(s)

There is a lot of hype about VSTO.  Most of it has to do with working across the network.  I have not seen anything about replacing plan old VBA code with say Visual Basic objects.  Yes, I know that VB is preferable to C# because of C# lack of optional args.  I have Eric Carter's book and it is of no help.  How do one man shops like myself use VSTO?  If VSTO us to replace VBA, then I need to see simple examples of how do it.