Creating Office commandbar controls:
button, pop-up, context menu for Outlook, Excel, Word
Commandbar / toolbar tips
Below we describe some important issues that you will probably run into when dealing with an Office commandbar (also referred to as toolbars), menus, their controls and menu items in Outlook, Excel, Word and other MS Office applications using Add-in Express .NET in VB.NET, C# or C++. To find more about advanced options and features that Add-in Express offers for customizing Office toolbars with .NET controls, please see a sample project showing how to add custom .NET control to Outlook toolbar.
In the Add-in Express Guide, elsewhere on the Add-in Express site, and in all our documents we use the terminology suggested by Microsoft for all toolbars, their controls, and for all interfaces of the Office Type Library. For example:
According to object model references, a pop-up control is a built-in or custom control on a menu bar or toolbar that displays a menu when clicked, or a built-in or custom menu item on a menu, submenu, or shortcut menu that displays a submenu when the pointer is positioned over it.
Pop-up button samples are View and View | Toolbars in the main menu and Draw in the Drawing toolbar in Word or Excel.
Add-in Express identifies all its controls (commandbar controls) through the use of the ControlTag property which is mapped to the Tag property of the CommandBarControl interface. The value of this property is generated automatically and you don't need to change it. For your own needs, use the Tag property instead.
According to the Microsoft's terminology, the term "pop-up" can be used for several controls: pop-up menu, pop-up button, and submenu. With Add-in Express, you can create a pop-up as using the Controls property of a command bar and then add any control to the pop-up via the Controls property of the pop-up.
However, pop-ups have an annoying feature: if an edit box or a combo box is added to a pop-up, their events are fired very oddly. Please don't regard this bug as that of Add-in Express.
You can connect an ADXCommandBar instance to any Office built-in commandbar. For example, you can add your own controls to the "Standard" commandbar or remove some controls from it. To do this just add to the add-in module a new ADXCommandBar instance and specify the name of the built-in command bar you need via the CommandBarName property.
Also, you can add any built-in controls to your own commandbar. To do this just add an ADXCommandBarControl instance to the ADXCommandBar.Controls collection and specify the Id of the built-in control you need via the Id property. To find out the built-in control IDs, use the free Built-in Controls Scanner utility.
Use the CommandBar.SupportedApps property to specify if the command bar is to appear in some or all host applications supported by the add-in. Unregister your add-in before you change the value of this property.
Add-in Express removes custom command bar(s) and controls when the add-in is uninstalled. However, this doesn't apply to Outlook and Access add-ins. You should set the Temporary property of custom command bars (and controls) to true to notify the host application that it can remove them itself. If you need to remove an Office commandbar or a button yourself, use the Tools | Customize dialog. See also Custom actions when your COM Add-in is uninstalled.
Use CommandBar.Position = adxMsoBarPopup option to display the CommandBar as a popup (context) menu. In the appropriate event handler, you write the following code:
The same applies to other command bar types.
Do you know, that all usual command bars that we used in earlier Office versions are still alive in Office 2007-2013 applications ( an exception is Outlook 2013)? Our free Built-in Controls Scanner reports that, say, Outlook 2007 email inspector still has the Standard toolbar with the Send button on it. This may be useful if the functionality of your add-in takes into account if this or that toolbar button is enabled or disabled.
As to custom toolbars, you can use set the UseForRibbon property of the corresponding component to true (the default value is false). This will result in your command bar controls showing up on the Add-ins tab along with command bar controls from other add-ins.
It looks like the ImageList has a bug: when you add images and then set the TransparentColor property, it corrupts the images in some way. Follow the steps below (at design-time) to get your images transparent:
It is easy to navigate down the command bar system: the host application supplies you with the Office.CommandBars interface that provides the Controls property returning a collection of the Office.CommandBarControls type. Office.CommandBarPopup provides the Controls property, too.
When navigating up the command bar system, you use the Parent property of the current object. For a command bar control (see Commandbar terminology) , this property returns Office.CommandBar. Note that the same applies to controls on a pop-up; command bars returned in this way aren't listed anywhere else in the command bar system. The parent for an Office.CommandBar is the host application. The parent for an Outlook command bar is either Outlook.Inspector or Outlook.Explorer.
ADXOlExplorerCommandBar and ADXOlInspectorCommandBar implement context-sensitive command bars; when the current folder correspond to the components' settings, the corresponding command bar is shown. To "manually" hide or show an inspector comand bar, you handle the InspectorActivate event of the Outlook Application Events component (ADXOutlookAppEvents) and set the Visible property of the ADXOlInspectorCommandBar to an appropriate value.
Explorer command bars are handled in the ExplorerFolderSwitch event (see ADXOutlookAppEvents). One thing to remember: you need to set ADXOlExplorerCommandBar.Enabled to true before you change ADXOlExplorerCommandBar.Visible to true. To hide an Outlook command bar "forever", you set the FolderName property of the corresponding command bar component so that it never matches any Outlook folder name.
If you didn't find the answer to your questions on this page, please see the HOWTOs section: