Outlook 2010 - Using onAction With A Built-In Button RRS feed

  • Question

  • Hi,

    I am using Visual Studio 2010 to customize the ribbons in Outlook 2010 and using the built in idMso button (OLPrintOptions) , but after this displays the dialog for the print options, is there anyway to call onAction to execute my own code?

    I'm not sure if onAction is the right way to solve my problem but essentially what I would like to do is display a dialog and then execute my code.


    XML -

    <button idMso="OLPrintOptions" label="Print Page Range" description="Prints a range of pages specified" onAction="printPageRangeMainRib" />


    VB -

    Sub printPageRangeMainRib(ByVal control As Office.IRibbonControl)


    End Sub

    Any help would be greatly appreciated



    Wednesday, February 19, 2014 10:44 AM

All replies

  • SendKeys may work, but in the wild it often doesn't work as you'd expect. It's a hack.

    You can repurpose existing ribbon buttons, but your code executes first and then either the built-in control code is executed or skipped depending on how you handle the repurposing. You cannot reverse the order though and fire your code after the built-in code.

    You could use the idMso of the control and use the CommandBars.ExecuteMso() command on an Explorer or Inspector's CommandBars collection. That would execute the ribbon control, after which you could call your own code.

    Other than that you'd need to code everything from scratch.

    For information on repurposing ribbon controls see

    Ken Slovak MVP - Outlook

    Wednesday, February 19, 2014 2:52 PM
  • > You can repurpose existing ribbon buttons

    Backstage UI controls cannot be intercepted/repurposed.

    A better solution would be to consider hiding the built-in UI and rebuilding it fully with custom commands.  

    Wednesday, February 19, 2014 3:09 PM
  • Hi Ken and Eugene,

    Thank you both for your suggestions. Ken mentioned maybe using the commandbars.ExecuteMso() method to execute the built in control, but I want to be able to execute the built-in button simply through my own custom button, not using a commandbar.

    Is there something similar to .ExecuteMso() that can be fired directly from my custom button?



    Thursday, February 20, 2014 9:55 AM
  • Hi Louis,

    Don't be confused with CommandBars name. The ExecuteMso is designed for calling Fluent UI built-in commands too, not only for command bars. MSDN states the following:

    Executes the control identified by the idMso parameter.

    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.

    Thursday, February 20, 2014 10:17 AM