Programmatically invoking the drop down item in C# form Outlook Add-in

1k Views Asked by At

I have a outlook add-in from which i want to invoke Ribbon Split button's drop down item using Redemption . This split button is a custom button created from other add-in. I want to access in my add-in. For detailed explanation check the below link.Invoking the Ribbon Split button using redemption When i tried accessing I am getting same error. Can some one help me to solve this problem. Here i am trying to invoke drop down item where in the other post that was trying to invoke button of the split button and moreover i have attached image which is very clear. Check the image in the link. (The link post was already posted by some one else in the stack overflow long back)

enter image description here

2

There are 2 best solutions below

6
Cindy Meister On BEST ANSWER

You cannot access buttons freely in the Office Ribbon, as was possible with the CommandBars interface - no matter what the programming language. This was a design decision on the part of Microsoft.

There are provisions for accessing the built-in controls provided by the Office application, as have been mentioned by others: CommandBars.ExecuteMso and the Accessibility APIs. These do not work for custom buttons, however.

It is possible to "share" another add-in's Ribbon controls, provided that add-in has used a namespace and the idQ attribute for the controls it shares. This does not enable your code to run the other add-ins code, however. (See this MSDN article: https://msdn.microsoft.com/en-us/library/aa338202(v=office.12))

The only possibility, but it's not a reliable one, is to use SendKeys (emulate the user typing) to send the Alt+keyboard shortcut combination for the command. The reason this is not reliable is because Office can alter the shortcut at any time, if it conflicts with any other shortcut present at that particular moment in the UI.

2
Eugene Astafiev On

If you need to execute an action of any control in Office applications you need to use the ExecuteMso method of the CommandBars class (see Explorer.CommandBars or Inspector.CommandBars). It allows to execute the control identified by the idMso parameter. Here is what MSDN states for the method:

This method is useful in cases where there is no object model for a particular command. Works on controls that are built-in buttons, toggleButtons and splitButtons. On failure it returns E_InvalidArg for an invalid IdMso, and E_Fail for controls that are not enabled or not visible.

You can find the list of built-in controls in the following documents:

In case if you need to run an action of any custom control which comes from another add-in you can call an event handler directly by using the late-binding technology represented by Reflection in .Net. See Type.InvokeMember method for more information. The approach is described in depth in the Calling Code in VSTO Add-ins from Other Office Solutions article.