Add Ribbon Control In Outlook 2013 Using Outlook 2013 Add-in In Visual Studio

Here I am describing how to add ribbon control inside Outlook mail.

Step 1: Open Visual Studio 2013 and then click on Office Add-ins. After that click Outlook 2013 Add-in.

Outlook 2013 Add-in

Step 2: Go to solution explorer and right click then add new items and new ribbon (XML).

ribbon

Step 3: Then write the same code inside XML file.

  1. <ribbon>  
  2.     <tabs>  
  3.         <tab id="TabAddIns" label="My Ribbon">  
  4.             <group id="Group1" label="Ribbon Options">  
  5.                 <button id="btnSettings" onAction="btnSettings_Click" imageMso="AdministrationHome" label="Settings" size="normal" />  
  6.                 <button id="btnHelp" onAction="btnHelp_Click" imageMso="Help" label="Get Help and Support" size="normal" /> </group>  
  7.             <group id="Group2">  
  8.                 <button id="BtnMy" imageMso="HappyFace" onAction="BtnMy_Click" label="My Button" size="large" /> </group>  
  9.         </tab>  
  10.         <tab id="TabAddIns1" label="My Ribbon1">  
  11.             <group id="Group11" label="Ribbon Options1">  
  12.                 <button id="btnSettings1" onAction="btnSettings_Click" imageMso="AdministrationHome" label="Settings" size="normal" />  
  13.                 <button id="btnHelp1" onAction="btnHelp_Click" imageMso="Help" label="Get Help and Support" size="normal" /> </group>  
  14.         </tab>  
  15.     </tabs>  
  16. </ribbon>  
Step 4: Then go to ribbon.cs file and write the same code.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.IO;  
  4. using System.Linq;  
  5. using System.Reflection;  
  6. using System.Runtime.InteropServices;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. using Office = Microsoft.Office.Core;  
  10. // TODO: Follow these steps to enable the Ribbon (XML) item:  
  11. // 1: Copy the following code block into the ThisAddin, ThisWorkbook, or ThisDocument class.  
  12. // protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()  
  13. // {  
  14. // return new MyRibbon();  
  15. // }  
  16. // 2. Create callback methods in the "Ribbon Callbacks" region of this class to handle user  
  17. // actions, such as clicking a button. Note: if you have exported this Ribbon from the Ribbon designer,  
  18. // move your code from the event handlers to the callback methods and modify the code to work with the  
  19. // Ribbon extensibility (RibbonX) programming model.  
  20. // 3. Assign attributes to the control tags in the Ribbon XML file to identify the appropriate callback methods in your code.   
  21. // For more information, see the Ribbon XML documentation in the Visual Studio Tools for Office Help.  
  22. namespace OutlookAddIn2  
  23. {  
  24.     [ComVisible(true)]  
  25.     public class MyRibbon: Office.IRibbonExtensibility  
  26.     {  
  27.         private Office.IRibbonUI ribbon;  
  28.         public MyRibbon()  
  29.         {}  
  30.         public void btnSettings_Click(Office.IRibbonControl control)  
  31.         {  
  32.             MessageBox.Show("Settings ");  
  33.         }  
  34.         public void BtnMy_Click(Office.IRibbonControl control)  
  35.         {  
  36.             MessageBox.Show("MyButton ");  
  37.         }  
  38.         public void btnHelp_Click(Office.IRibbonControl control)  
  39.         {  
  40.             MessageBox.Show("Help ");  
  41.         }#region IRibbonExtensibility Members  
  42.         public string GetCustomUI(string ribbonID)  
  43.         {  
  44.             return GetResourceText("OutlookAddIn2.MyRibbon.xml");  
  45.         }#endregion# region Ribbon Callbacks  
  46.         //Create callback methods here. For more information about adding callback methods, visit http://go.microsoft.com/fwlink/?LinkID=271226  
  47.         public void Ribbon_Load(Office.IRibbonUI ribbonUI)  
  48.         {  
  49.             this.ribbon = ribbonUI;  
  50.         }#endregion# region Helpers  
  51.         private static string GetResourceText(string resourceName)  
  52.         {  
  53.             Assembly asm = Assembly.GetExecutingAssembly();  
  54.             string[] resourceNames = asm.GetManifestResourceNames();  
  55.             for (int i = 0; i < resourceNames.Length; ++i)  
  56.             {  
  57.                 if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)  
  58.                 {  
  59.                     using(StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))  
  60.                     {  
  61.                         if (resourceReader != null)  
  62.                         {  
  63.                             return resourceReader.ReadToEnd();  
  64.                         }  
  65.                     }  
  66.                 }  
  67.             }  
  68.             return null;  
  69.         }#endregion  
  70.     }  
  71. }  
Step 5: Then build it and run the application.

After that all custom ribbon will be shown on top of the outlook mailbox.

custom ribbon

Here I have described each line of the code plus posted all screenshots.

Please go through that and develop on your own.

 

Up Next
    Ebook Download
    View all
    Learn
    View all
    Rotary International is an international service organization whose stated purpose is to bring toget