[Sample of May 6th] Customize Outlook UI with Ribbon XML
![]() | ![]() | |
![]() | ![]() |
Sample Downloads: https://code.msdn.microsoft.com/VBOutlookRibbonXml-bc478854
Today’s sample demonstrates how to customize Microsoft Outlook UI using the Ribbon XML.
You can find more code samples that demonstrate the most typical programming scenarios by using Microsoft All-In-One Code Framework Sample Browser or Sample Browser Visual Studio extension. They give you the flexibility to search samples, download samples on demand, manage the downloaded samples in a centralized place, and automatically be notified about sample updates. If it is the first time that you hear about Microsoft All-In-One Code Framework, please watch the introduction video on Microsoft Showcase, or read the introduction on our homepage https://1code.codeplex.com/.
Introduction
The VBOutlookRibbonXml provides the examples on how to customize Office UI using the Ribbon XML. This sample also shows a way on how to keep & track the same control's property status (e.g. Checked) in different inspectors.
Building the sample
- You must install office 2010 in your Operation System.
- This project references the Primary Interop Assembly (PIA )for Microsoft Office Outlook 2010.
- Be sure that your Outlook2010 is not running when building sample.
Running the Code
When you run the code, an Outlook was launched. Click ��New E-mail�� in ��Home�� tab. A new e-mail window shows out with “Sample Tab” tab.
Using the Code
1. We need to create an XML file containing description of our customized Ribbon contents.
<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load" loadImage="LoadImage" xmlns="https://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab idMso="TabAddIns" label="Sample Tab" keytip="FT">
<group id="grpOne" label="Group One">
<button id="btnWeb" onAction="btnWeb_OnAction" label="Project Home" size="large" image="Globe" />
<separator id="separator1" />
<comboBox id="cboMyList" imageMso="FormControlComboBox" supertip="This is a ComboBox
Drop down and Edit are both enabled." label="ComboBox:">
<item id="__id2" label="Item0" />
<item id="__id3" label="Item1" />
<item id="__id4" label="Item2" />
</comboBox>
<toggleButton id="tbSecondTab" imageMso="ControlTabControl" onAction="tbSecondTab_OnAction" getPressed="tbSecondTab_GetPressed" label="Second Tab" />
<checkBox id="chkShowGroup" onAction="chkShowGroup_OnAction" getPressed="chkShowGroup_GetPressed" label="Group Three" />
<dialogBoxLauncher>
<button id="grpOneDlgLauncher" onAction="grpOneDlgLauncher_OnAction" />
</dialogBoxLauncher>
</group>
<group id="grpTwo" label="Group Two">
<splitButton id="splitButton">
<button id="splitButton__btn" imageMso="AlignLeft" label="SplitButton" onAction="splitButton_Click" />
<menu id="splitButton__mnu">
<button id="btnAlignLeft" imageMso="AlignLeft" onAction="btnAlign_Click" label="Left" />
<button id="btnAlignCenter" imageMso="AlignCenter" onAction="btnAlign_Click" label="Center" />
<button id="btnAlignRight" imageMso="AlignRight" onAction="btnAlign_Click" label="Right" />
</menu>
</splitButton>
<editBox id="txtEdit" imageMso="ActiveXTextBox" onChange="txtEdit_OnChange" label="Edit Box:" />
<labelControl id="lblSample" getLabel="lblSample_GetLabel" />
</group>
<group id="grpThree" label="Group Three" getVisible="GetVisible">
<buttonGroup id="buttonGroup1">
<button id="btnOne" label="One" showImage="false" />
<button id="btnTwo" label="Two" showImage="false" />
<button id="button10" label="Three" showImage="false" />
</buttonGroup>
<dynamicMenu id="mnuSample" imageMso="HappyFace" label="Menu Sample" getContent="Ribbon_GetContent" />
<separator id="separator3" />
<gallery id="glrCd" label="Disk Gallery" size="large" image="BlankCD">
<item id="glrAudioCD" label="Audio CD" image="AudioCD" />
<item id="glrAudioCDPlus" label="Audio CD Plus" image="AudioCDPlus" />
<item id="glrAudioDVD" label="Audio DVD" image="AudioDVD" />
<item id="glrBDMovie" label="BD Movie Disk" image="BDMovie" />
<item id="glrBlankCD" label="Blank CD" image="BlankCD" />
<item id="glrVCD" label="VCD" image="VCD" />
<button id="btnBurnDisk" label="Burn Disk" image="BurnCD" />
</gallery>
</group>
</tab>
<tab id="mySecondTab" label="Second Sample Tab" getVisible="GetVisible">
<group id="grpMail" label="Mail Item" getVisible="GetVisible">
<labelControl id="lblMailMode" getLabel="lblMainMode_GetLabel" />
</group>
<group id="grpAppointmentItem" label="Appointment Item" getVisible="GetVisible">
<labelControl id="label1" label="This is an Appointment Item" />
</group>
<group id="grpTaskItem" label="Task Item" getVisible="GetVisible">
<labelControl id="label2" label="This is a Task Item" />
</group>
<group id="grpContactItem" label="Contact Item" getVisible="GetVisible">
<labelControl id="label3" label="This is a Contact Item" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
2. Create a class that implements the Microsoft.Office.Core.IRibbonExtensibility class.
<Runtime.InteropServices.ComVisible(True)> _
Public Class Ribbon
Implements Office.IRibbonExtensibility
3. In Ribbon.vb, implement the GetCustomUI (memeber of IRibbonExtensibility) method. In this method, we return Ribbon XML according to the RibbonID passed in.
Public Function GetCustomUI(ByVal ribbonID As String) As String Implements Office.IRibbonExtensibility.GetCustomUI
' We will show our customized Ribbon on the following types of
' inspectors
If ribbonID = "Microsoft.Word.Document" Or _
ribbonID = "Microsoft.Outlook.Mail.Read" Or _
ribbonID = "Microsoft.Outlook.Mail.Compose" Or _
ribbonID = "Microsoft.Outlook.MeetingRequest.Read" Or _
ribbonID = "Microsoft.Outlook.MeetingRequest.Send" Or _
ribbonID = "Microsoft.Outlook.Appointment" Or _
ribbonID = "Microsoft.Outlook.Contact" Or _
ribbonID = "Microsoft.Outlook.Task" Then
Return GetResourceText("VBOutlookRibbonXml.Ribbon.xml")
Else
Return Nothing
End If
End Function
4. In Ribbon.vb, implement the callback methods
More Information
�� Customizing the Ribbon in Outlook 2007
Comments
Anonymous
May 12, 2015
Thank you for this very useful sample. Could you please tell us how to capture gallery item's click? I spent whole day searching but nothing so far .. Thank you.Anonymous
May 18, 2015
How to split the combobox items by a text or label as Outlook does in case of Fonts Combobox.. in this case by "all fonts" and "theme fonts"??