none
How can I collapse the entire ribbon when editing a new mail message? RRS feed

  • Question

  • I am trying to automatically collapse the ribbon when a message compose window is opened.  The ribbon can be collapsed by the user by typing Ctrl + F1.  If this were an Add-In for Microsoft Word, I think this would be accomplished by executing

    Globals.ThisAddIn.Application.ActiveWindow().ToggleRibbon();

    However, since this is an Outlook Add-In it appears to be more difficult.  I want this to be done when the compose window is first opened so I have added an Activate event handler on the inspector.  From within the Activate event handler I am trying to execute this code:

    Microsoft.Office.Interop.Word.Document wd = inspector.WordEditor as Microsoft.Office.Interop.Word.Document;
    Microsoft.Office.Interop.Word.Window w = wd.ActiveWindow as Microsoft.Office.Interop.Word.Window;
    
    if (w != null)
    {
    	w.ToggleRibbon();
    }

    Unfortunately I get an exception on the second line:

    This object model command is not available in e-mail.

    How can I collapse the ribbon when a new mail compose window is opened?

    Thanks.

    Thursday, May 1, 2014 6:50 PM

Answers

  • I think a much easier way to do this is to use the idMSO "MinimizeRibbon" and use the CommandBars.ExecuteMso("MinimizeRibbon") command.

    Even though deprecated the Inspector.CommandBars object can be used to get the needed CommandBars object, from there the code is easy. If necessary CommandBars can be gotten using late binding or reflection instead of early binding.


    Ken Slovak MVP - Outlook

    • Marked as answer by Joy Peterson Friday, May 2, 2014 5:58 PM
    Friday, May 2, 2014 3:20 PM

All replies

  • Hello Joy,

    You code will not work. Outlook and Word have entirely different object models.

    Unfortunately the Fluent UI doesn't provide any property or method for collapsing the ribbon (see IRibbonUI ). There is no trivial way for implementing the required functionality. You can try using Accessibility API or Windows API functions.

    Thursday, May 1, 2014 7:08 PM
  • I think a much easier way to do this is to use the idMSO "MinimizeRibbon" and use the CommandBars.ExecuteMso("MinimizeRibbon") command.

    Even though deprecated the Inspector.CommandBars object can be used to get the needed CommandBars object, from there the code is easy. If necessary CommandBars can be gotten using late binding or reflection instead of early binding.


    Ken Slovak MVP - Outlook

    • Marked as answer by Joy Peterson Friday, May 2, 2014 5:58 PM
    Friday, May 2, 2014 3:20 PM
  • Thank you for the tip Ken.  Any chance you could tell me how to load CommandBars using late binding?  I have never done something like that before.  I am searching for hints now, but if you know it will save me some time.

    Friday, May 2, 2014 5:02 PM
  • The easiest way to do that is to declare the object as "dynamic" and then just use Inspector.CommandBars:

    dynamic bars = Inspector.CommandBars;


    Ken Slovak MVP - Outlook

    Friday, May 2, 2014 5:20 PM
  • Thank you for the help Ken.  Here is my solution:

    dynamic cb = inspector.CommandBars;
    
    // On my system the height is 147 when the ribbon is expanded and 61 when the ribbon is collapsed but this may vary depending on the system so choose a value somewhere in the middle to determine if the ribbon is currently expanded.
    if (cb["Ribbon"].Height > 80)
    {
        cb.ExecuteMso("MinimizeRibbon");
    }

    Friday, May 2, 2014 5:57 PM
  • Get the height before you make any calls and if it's over a certain value save and use the value you fetch. That would compensate for display and other sizing variables.

    Ken Slovak MVP - Outlook

    Friday, May 2, 2014 6:00 PM