none
Outlook 2007 add-in using VS2013 RRS feed

  • Question

  • Hello,

    I am in process of creating add-ins for all MS Office products. I have been using VS2013 for development. The user base has a variety of Office versions spanning Office 2007 to Office 2013. The add-ins that I created so far for Word, Excel and PowerPoint have worked well in all the Office versions. However, the add-in that I am creating for Outlook doesn't seem to be working on Outlook 2007. I realize that the way menus are handled in Outlook 2007 is different compared to Outlook 2010 onwards. My add-in needs to have a menu but VS2013 allows me to create ribbon menus which are not supported in Outlook 2007.

    Can someone please suggest me a way of creating menus that will work in all the versions of Outlook? I have been stuck with this for some time now and any help or advice will be greatly appreciated.

    Thanks

    Monday, September 14, 2015 10:31 AM

Answers

  • Hello,

    The fact is that Office 2007 is the first Office version when the Ribbon UI was introduced. Not all Office applications used the new UI. Instead, the Command Bars were used. So, you just need to use CommandBars class for adding custom UI to older Office applications. For example:

    Set newItem = CommandBars("Tools").Controls.Add(Type:=msoControlButton) 
    With newItem 
        .BeginGroup = True  
        .Caption = "Make Report" 
        .FaceID = 0 
        .OnAction = "qtrReport" 
    End With

    The Fluent UI is used for customizing context menus starting from the Office 2010. See Customizing Context Menus in Office 2010 for more information.

    Monday, September 14, 2015 12:10 PM
  • I came up with below code which has worked for me:

     private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
    if (Convert.ToInt32(this.CheckVersion()) < 14)
    {
    CommandBar myCommandBar = this.Application.ActiveExplorer().CommandBars.Add("MyBar", MsoBarPosition.msoBarTop, false, true);
    myCommandBar.Visible = true;

    CommandBarControl cmdBarControl2 = myCommandBar.Controls.Add(MsoControlType.msoControlButton, 1, "", Missing.Value, true);
    cmdBarControl2.Visible = true;
    cmdBarControl2.Caption = "My Bar";
    CommandBarButton btnclickhandler = (CommandBarButton)cmdBarControl2;
    btnclickhandler.Click += btnclickhandler_Click;
    }
    }

    • Marked as answer by RoJoshi Monday, September 21, 2015 10:23 AM
    Monday, September 21, 2015 10:05 AM

All replies

  • Hello,

    The fact is that Office 2007 is the first Office version when the Ribbon UI was introduced. Not all Office applications used the new UI. Instead, the Command Bars were used. So, you just need to use CommandBars class for adding custom UI to older Office applications. For example:

    Set newItem = CommandBars("Tools").Controls.Add(Type:=msoControlButton) 
    With newItem 
        .BeginGroup = True  
        .Caption = "Make Report" 
        .FaceID = 0 
        .OnAction = "qtrReport" 
    End With

    The Fluent UI is used for customizing context menus starting from the Office 2010. See Customizing Context Menus in Office 2010 for more information.

    Monday, September 14, 2015 12:10 PM
  • Thanks Eugene. Would you happen to know C# example of using CommandBars class? I am still struggling with it.
    Tuesday, September 15, 2015 3:55 AM
  • The Add method is used for adding new controls. Take a look at the sample code listed in my previous post there.

    Tuesday, September 15, 2015 6:38 AM
  • I came up with below code which has worked for me:

     private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
    if (Convert.ToInt32(this.CheckVersion()) < 14)
    {
    CommandBar myCommandBar = this.Application.ActiveExplorer().CommandBars.Add("MyBar", MsoBarPosition.msoBarTop, false, true);
    myCommandBar.Visible = true;

    CommandBarControl cmdBarControl2 = myCommandBar.Controls.Add(MsoControlType.msoControlButton, 1, "", Missing.Value, true);
    cmdBarControl2.Visible = true;
    cmdBarControl2.Caption = "My Bar";
    CommandBarButton btnclickhandler = (CommandBarButton)cmdBarControl2;
    btnclickhandler.Click += btnclickhandler_Click;
    }
    }

    • Marked as answer by RoJoshi Monday, September 21, 2015 10:23 AM
    Monday, September 21, 2015 10:05 AM
  • Thank you for sharing the code for other forum readers. 

    First, if you want to get the following event fired:

    btnclickhandler.Click += btnclickhandler_Click;

    you need to declare the source object at the global scope.

    Second, I always recommend breaking the chain of property and method calls and declare them on separate lines of code:

    this.Application.ActiveExplorer().CommandBars.Add


    Monday, September 21, 2015 10:12 AM