Making a Custom Group Appear in the Message Tab of a Mail Item (Norm Estabrook)
You can add a custom group to the Message tab of an Outlook mail item. For example, here is a custom group named "MyCoolGroup" that I added to the message tab of a new message:
Outlook lets you open a message in the following two modes:
- Compose (you are drafting a new message).
- Read (you are reading a message).
Making a custom group appear for only one of these modes is pretty easy. Making it appear for both modes is a tad more challenging. That is because the control ID of the Message tab in read mode is different than the control ID of the Message tab in compose mode. When you design your custom group in the VSTO Ribbon designer, you can only specify one control ID. This means that when you run the project, the custom group will only appear in the Message tab of a compose window or the Message tab of a read window depending on which control ID you specify at design-time.
If you want the group to appear in both versions of the Message tab (read and compose), you have to do a bit more work. Here is how you make the group appear for both modes:
First, add a Ribbon (Visual Designer) to an Outlook 2007 add-in project.
Then, set the RibbonType property of the Ribbon to Microsoft.Outlook.Mail.Compose and Microsoft.Outlook.Mail.Read as follows:
On the Ribbon designer, add a group to a tab and customize the group as desired.
On the Ribbon designer, select the tab, open the Properties window, and then set the OfficeId of the tab to TabReadMessage. TabReadMessage is the control ID of the default tab that appears on the Ribbon of a mail message that is open in read mode.
Ok. Now when you run the project, your custom group will appear only if you open a mail item in read mode. Now you need to add a little code to display the custom group in the Message tab of a new mail item. That is, a mail item that you open in compose mode.
To do this, create an event handler for the NewInspector event. This event is raised every time a new Outlook inspector is open. In the event handler, check the EntryID property of the mail item. If this property is null, then the item is a new message. If that is the case, set the OfficeId property of the tab to TabNewMailMessage. TabNewMailMessage is the control ID of the Message tab of a mail message in compose mode.
private Outlook.Inspectors inspectors;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
inspectors = this.Application.Inspectors;
inspectors.NewInspector +=
new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler
(Inspectors_NewInspector);
}
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
Outlook.MailItem tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem;
if (tmpMailItem != null)
{
if (tmpMailItem.EntryID == null)
Globals.Ribbons.Ribbon1.tab1.ControlId.OfficeId = "TabNewMailMessage";
}
}
You can read more about adding custom groups to built-in tabs in the following MSDN articles:
How to: Customize a Built-in tab
How to: Get Started Customizing the Ribbon
Ribbon Designer
Customizing a Ribbon for Outlook
This login represents the Visual Studio Tools for Office team. Many members of the team us this account for publishing technical blog posts.