Tips for creating Office commandbar / toolbar controls:
button, pop-up, context menu for Outlook, Excel, Word

Add-in Express
for Microsoft .net


Add-in Express Home > Add-in Express.NET > Online Guide > Commandbar tips

Commandbar / toolbar tips

Creating COM add-ins in Visual Studio .NET - Flash video 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.

Command bar terminology

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:

  • Command bar is a toolbar or a menu bar.
  • Command bar control is one of the following: a button, an edit box, a combo box, or a pop-up.
  • Pop-up can stand for a pop-up menu, a pop-up button on a command bar or a submenu on a menu bar.

Add the COM Add-ins command to an Office commandbar or menu

To add the COM Add-ins command to an Office commandbar or menu, you do the following:

  • Open the host application (Outlook, Excel, Word, etc) 
  • On the Tools menu, click Customize.
  • Click the Commands tab. 
  • In the Categories list, click the Tools category.
  • In the Commands list, click COM Add-Ins and drag it to a toolbar or menu of your choice.

Built-in and custom command bars in Ribboned Office 2007 applications

Do you know, that all usual command bars that we used in earlier Office versions are still alive in Office 2007 applications? Our free Built-in Controls Scanner reports that, say, Outlook 2007 e-mail 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.

ControlTag vs. Tag property

Add-in Express identifies all its controls (commandbar controls) through the use of the ControlTag property (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.

Pop-ups

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 your own pop-up as an element of your controls commandbar collection and add to it any control via the Controls property. But pop-ups have a feature that is very annoying: if an edit box or a combo box is added to a pop-up, their events are fired very oddly. Don’t regard this bug as that of Add-in Express. It seems to be intended by Microsoft.

Edit and combo boxes and the Change event

The Change event appears only when the value was changed and the focus was shifted. This is also not our bug but Microsoft guys’ “trick”.

Built-in controls and command bars

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.

Outlook CommandBar visibility rules

Add-in Express displays the Explorer commandbar for every folder, which name AND type correspond to the values of FolderName, FolderNames, and ItemTypes properties. For the Inspector toolbar, the same rule applies to the folder in which an Outlook Item is opened or created.

Removing custom commandbar and controls

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.

COM add-ins for Outlook – template characters in FolderName

Regardless of the fact that the default value of the FolderName property is '*' (asterisk), which means "every folder", the current version doesn't support template characters in the FolderName(s) property value. Moreover, this is the only use of the asterisk recognizable in the current version.

How to make a command bar show up in some or all supported host applications

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.

How to display CommandBar as a popup (context) menu

Use CommandBar.Position = adxMsoBarPopup option to display the CommandBar as a popup (context) menu. In the appropriate event handler, you write the following code:


AdxOlExplorerCommandBar1.CommandBarObj.GetType.InvokeMember("ShowPopup", _ 
    Reflection.BindingFlags.InvokeMethod, Nothing, _ 
    AdxOlExplorerCommandBar1.CommandBarObj, Nothing)

The same applies to other command bar types.

Transparent icon on a CommandBarButton

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: 

  • Make sure the ImageList doesn't contain any images
  • Set its TransparentColor property to Transparent
  • Add images to the ImageList
  • Choose an image in the Image property of your command bar button
  • Specify the transparent color in the ImageTransparentColor property of the command bar button
  • Rebuild the project.

See also some tips about:

Note, If you didn't find the answer to your questions on this page, please see the HOWTOs section:

COM add-in tips <<

>> Office 2007 Ribbon tips

Back to Add-in Express.NET homepage




Client login

 

Login 

Password 

 

Remember me

Forgot my password