title: c# Excel - Display ribbon on exit
body: <p>I'm using VSTO to design an application with an Excel interface. I want to hide the ribbon on startup (shouldn't be needed in the application) and re-display it on exit (if the user had it originally displayed), to avoid irritating people who use the application and want a ribbon the next time they open Excel.</p>
  
  <p>I can hide the ribbon using essentially the following code in <code>ThisWorkbook_Startup</code> (from this question <a href="https://stackoverflow.com/questions/12514660/excel-2007-minimize-the-ribbon-programatically-but-not-the-menu-bar">Excel 2007 Minimize the Ribbon programatically but Not the menu bar</a>):</p>
  
  <pre><code>        Office.CommandBars cbs = null;
          cbs = Application.CommandBars;
  
          foreach (Office.CommandBar commandBar in cbs)
          {
              if (commandBar.Name == "Ribbon")
              {
                  this.Application.ActiveWindow.Activate();
                  Application.SendKeys("^{F1}", true);
              }
          }
  </code></pre>
  
  <p>However, the same code or similar variations from the previously referenced question do not seem to work when placed in either the <code>ThisWorkbook_Shutdown</code> or <code>ThisWorkbook_BeforeClose</code> methods. The code is hit but never seems to execute - the ribbon is never restored.</p>
  
  <p>Is there another way to restore the ribbon on exit?</p>
  
  <p>Thanks,</p>
  
  <p>Andrew</p>