Appendix B. Creating Inspector CommandBars

In VBA, when you add a button to a CommandBar, you associate a macro with the OnAction property of the button. Using VSTO, you must programmatically create a CommandBarButton and add it to the CommandBar.

Outlook presents some challenges when you’re creating CommandBars and CommandBarButtons. For every CommandBarButton that you create, you must hold a reference to it in order for the Click event handler to function properly. In this example, we show you how to create an Inspector CommandBar and add a button to it.

  1. Create an Outlook add-in using VSTO.
  2. Add the code in Listing B.1 to the Startup event handler of ThisApplication, and add the variables with events at the class level.

    Listing B.1. Creating ...

Get VSTO for Mere Mortals™: A VBA Developer’s Guide to Microsoft Office Development Using Visual Studio 2005 Tools for Office 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.