Original post:
When Outlook is launched, the Add-In is loaded and adds a toolbar with some buttons.
toolBar = OutlookApp.ActiveExplorer().CommandBars.Add(MENU_TAG, MsoBarPosition.msoBarTop, false, true);
Everything was working fine, but now one user has his Outlook shortcut set to launch Outlook minimized.
And then OutlookApp.ActiveExplorer() return null. Is there some event I can use to catch when there is an ActiveExplorer and then add the commandbar?
OutlookApp.Explorers.NewExplorer doesn't work.
Also, when I show a messagebox before I add the CommandBar: everything works fine, even with Outlook minimized... Why?
edit:
Accessing the Explorers proprerty directly did work, as someone said in the answers. So this solves the problem for a minimized outlook... But...
One of the users does not have Outlook run minimized, and still the plugin loads before any gui is available. There are not even 1 explorer in the Explorers collection :( How is this possible?
edit 2:
I tried using a timer as suggested by 76mel, checking ActiveExplorer for null every 100ms. This adds the buttons as expected, but I can set the Picture property of the button.
I get this exception:
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
If there is no UI = no explorer :(
Try waiting until the Explorers.NewExplorer event fires to be able to get a CommandBars object.
Update: Yes it looks like a timer will do the trick ok a bit hacky. So wire up a timer when you have a null ActiveExplorer and check for the ActiveExplorer onTick. Once the user pops outlook you get you active explorer and you can then add you tool bars.
I'm not familiar with managed addins, but I found this answer. If there is no ActiveExplorer, try to access the Explorers collections directly, like in Explorers[1].
I had the same problem in my ECE and solved it by waiting for OnObjectChange callback that would be called when the user changes a folder in Outlook, and then I try to recreate the toolbar. This might roughly correspond to the FolderSwitch event in the Outlook object model.
Just my 2c.
User contributions licensed under CC BY-SA 3.0