none
Addin fails in Outlook 2016 when accessing explorer.selection property on startup RRS feed

  • Question

  • This code works perfectly for Outlook 2010 and 2013 (32&64 bit). On startup the ribbon enablehandler is called to set which buttons are enabled.

      Public Function OneItemSelected() As Boolean
            If _explorer.CurrentFolder.WebViewOn Then Return False
            If _explorer.Selection Is Nothing Then Return False
            Return (_explorer.Selection.Count = 1)
        End Function

    I am using the reference to the 2013 PIAs. Do I need a newer version to work with 2016?

    C:\Program Files (x86)\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA\Office15\Microsoft.Office.Interop.Outlook.dll

    Here is the error info

    Error: The operation failed. Stack Trace: at Microsoft.Office.Interop.Outlook.ExplorerClass.get_Selection() at OtgAddin.MyExplorer.OneItemSelected() at OtgAddin.MyRibbon.EnableHandler(IRibbonControl Ctrl)

    Friday, May 20, 2016 2:45 PM

All replies

  • Does it only happen on startup? Keep in mind that the explorer might not be initialized, or might not even exist when your addin is being loaded.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, May 20, 2016 4:47 PM
  • Thanks Dmitry.  This is a normal Outlook startup from a desktop icon.  The ribbon events are being called for the explorer ribbon, so I would assume the explorer exists at this point.  This same code works in 2010 and 2013.  So what in 2016 is different?

    Here is my event log

    05-17-16 22:38:53.930 INFO ========================================
    05-17-16 22:38:53.931 INFO ThisAddIn.ThisAddin_Startup: Addin Starting
    05-17-16 22:38:53.947 INFO Controller.InitHandler
    05-17-16 22:38:53.947 INFO Controller.InitHandler - Normal Outlook Startup
    05-17-16 22:38:53.947 INFO Controller.InitHandler - Check Version
    05-17-16 22:38:53.978 INFO Controller.InitHandler - License Status: Activated
    05-17-16 22:38:53.988 INFO MyExplorer(1).New
    05-17-16 22:38:54.065 INFO ProfileSettings.Load - Open Folder - 0.005
    05-17-16 22:38:54.082 INFO ProfileSettings.Load - Find Settings Item - 0.017
    05-17-16 22:38:54.094 INFO ProfileSettings.Load - Extract XML - 0.012
    05-17-16 22:38:54.101 INFO ProfileSettings.Load - LoadXML - 0.007
    05-17-16 22:38:54.101 INFO Controller.InitHandler - Settings Loaded
    05-17-16 22:38:54.132 INFO Controller.InitHandler - Finished 0.185
    05-17-16 22:38:54.132 INFO MyRibbon.Init
    05-17-16 22:38:54.237 INFO MyExplorer(1)._explorer_FolderSwitch (\\xxxxxxxx\Inbox)
    05-17-16 22:38:54.326 INFO MyRibbon.GetCustomUI - Microsoft.Outlook.Explorer
    05-17-16 22:38:54.331 INFO MyRibbon.RibbonOnLoad
    ========================================
    05-17-16 22:38:54.357 ERR! Ctrl.Id = Explorer.Mail.Schedule, Ctrl.Tag = Explorer.Schedule [Microsoft Outlook] The operation failed.
    Stack Trace:    at Microsoft.Office.Interop.Outlook.ExplorerClass.get_Selection()
       at OtgAddin.MyExplorer.OneItemSelected()
       at OtgAddin.MyRibbon.EnableHandler(IRibbonControl Ctrl)

    Friday, May 20, 2016 6:12 PM
  • Hello,

    Where did you get the _explorer object? 

    Anyway, I'd suggest using the IRibbonControl.Context property which represents the active window containing the Ribbon user interface that triggers a callback procedure. Note, an instance of the IRibbonControl interface is passed to Ribbon callbacks.  You can read more about the Fluent UI (aka Ribbon UI) in the following series of articles:

    1. Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)

    2. Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)

    3. Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)


    [custom.development]

    Friday, May 20, 2016 10:25 PM
  • Hi gbellpublic,

    According to your description, I have made a sample to try to reproduce this issue with Outlook 2016, unfortunately, I can't. You could refer to below code:

    Ribbon(XML)
    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab idMso="TabAddIns">
            <group id="MyGroup"
                   label="My Group">
              <button id="btnOn" getEnabled="GetEnabled" label="Test"/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
    getEnabled callback:
    public bool GetEnabled(Office.IRibbonControl control)
    { 
        if(Globals.ThisAddIn.Application.ActiveExplorer().CurrentFolder.WebViewOn)
        {
            return false;
        }
        if (Globals.ThisAddIn.Application.ActiveExplorer().Selection == null)
        {
            return false;
        }
        return (Globals.ThisAddIn.Application.ActiveExplorer().Selection.Count==1);
    }
    So I suggest that you could provide sample code about getting the explorer object, that will help us reproduce and resolve your issue.

    Thanks for your understanding.
    Monday, May 23, 2016 8:50 AM
  • David,

    Thank you for your idea.  I had the customer try and get the same result.  This was my first 2016 customer, so I hoped it would work.  In the meantime I purchased Outlook 2016 and installed my addin.  It works in a 2016 POP3 environment with no problem.   So I asked the customer what their mail transport was and the reply was Office 365 Public Multi Tenant.  I am thinking this is the problem.  Can addins run in this environment with some tweaking?  

    Some additional information

    ProductVersion: 1.0.35 64-bit
    WindowsVersion: 10.0.10586.0 - Microsoft Windows 10 Pro 64-bit
    OfficeVersion: 16.0.0.6868 - Office 2016 64-bit
    ProductSite:
    http://fyreware.com/otg

    Thursday, May 26, 2016 1:44 AM
  • Hi gbellpublic,

    I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

    Thanks for your understanding.
    Monday, May 30, 2016 9:56 AM
  • Thank you David, I appreciate you looking into this.
    Wednesday, June 15, 2016 3:27 PM