Customizing Office 2007 Ribbons and ribbon controls in
C#, C++, VB.NET - tips for developers

Add-in Express™
for Microsoft® Office and .net

Add-in Express Home > Add-in Express .NET > Online Guide > Office 2007 Ribbon tips

Office 2007 ribbons tips

Writing Office 2007 - 2000 COM add-ins in Visual Studio .NET - Flash video Add-in Express provides a visual designer for customizing Office 2007 Ribbon tabs. It also offers special features for advanced customization of Office 2007 Ribbon UI, Quick Access Toolbar and Office Menu. On this page you can find some tips about dealing with Office 2007 ribbons and ribbon controls.

Being ribboned

Find IDs of built-in Ribbon controls in 2007 Office System Document: Lists of Control IDs at Microsoft web-site.

Sharing Office 2007 Ribbon controls across multiple add-ins

First off, you assign the same string value to the AddinModule.Namespace property of every add-in that will share your Ribbon controls. This makes Add-in Express add two xmlns attributes to the customUI tag in the resulting Xml markup:

  • xmlns:default="%ProgId of your add-in, see the ProgID attribute of the AddinModule class%"
  • xmlns:shared="%the value of the AddinModule.Namespace property%".

Originally, all the Ribbon controls are located in the default namespace (id="%Ribbon control's id%" or idQ="default:%Ribbon control's id%") and you have full control over them via callbacks provided by Add-in Express. When you specify the Namespace property, Add-in Express changes the markup to use idQ's instead of id's.

Then, in all the add-ins that are to share an Office 2007 Ribbon control, for the control with the same Id (you can change the Id's to match), you set the Shared property to True. For the Ribbon control whose Shared property is True, Add-in Express changes its idQ to use the shared namespace (idQ="shared:%Ribbon control's id%") instead of the default one. Also, for such Ribbon controls, Add-in Express cuts out all the callbacks and replaces them with "static" versions of the attributes. Say, getVisible="getVisible_CallBack" will be replaced with visible="%value%".

The shareable Ribbon controls are the following Ribbon container controls:

  • Ribbon Tab - ADXRibbonTab
  • Ribbon Box - ADXRibbonBox
  • Ribbon Group - ADXRibbonGroup
  • Ribbon Button Group - ADXRibbonButtonGroup

When referring to a shared Office 2007 Ribbon control in the BeforeId and AfterId properties of another Ribbon control, you use the shared controls' idQ: %namespace abbreviation% + ":" + %control id%. The abbreviations of these namespaces are "default" and "shared" string values. The resulting XML markup may look like this:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
          xmlns:default="MyOutlookAddin1.AddinModule"
          xmlns:shared="MyNameSpace" [callbacks omitted]>
 <ribbon>
  <tabs>
   <tab idQ=" shared:adxRibbonTab1" visible="true" label="My Tab">
    <group idQ="default:adxRibbonGroup1" [callbacks omitted]>
     <button idQ="default:adxRibbonButton1" [callbacks omitted]/>
    </group>
   </tab>
  </tabs>
 </ribbon>
</customUI>

In the XML-code above, the add-in creates a shared tab, containing a private group, containing a button (private again).

Intercepting built-in Ribbon controls

To repurpose a Ribbon control, you use the Ribbon Command component. It provides a cancellable event called OnAction. Another use of the component is shown in the screenshot below; the following settings make the Copy command in Word 2007 disabled:

Disabling a command in Word 2007

Dynamic Ribbon controls

The Office 2007 Ribbon is a static thing from birth; the only control providing any dynamism is Dynamic Menu (see the Dynamic property of the ADXRibbonMenu component). For other controls, you can only imitate that dynamism by changing the Visible property of a Ribbon control.

Cannot add a Ribbon control

The Ribbon tab designer performs the XML-schema validation automatically, so from time to time you will run into the situation when you cannot add a control to some level. It is a restriction of the Ribbon XML-schema.

Customizing Quick Access Toolbar

Microsoft require developers to use the StartFromScratch parameter (see the StartFromScratch property of the add-in module) when customizing the Quick Access Toolbar.

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 supporting the Ribbon UI? For instance, our free Built-in Controls Scanner reports that 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 Office 2007 add-in takes into account the enabled / disabled state of this or that toolbar button.

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.

Note. If you didn't find the answer to your questions about MS Office 2007 Ribbon on this page, please see the HOWTOs section:

Commandbar tips <<

>> Excel UDF and RTD tips

Back to Add-in Express .NET homepage

Have any questions? Ask us right now!