VSTO Word activate ribbon tab

Patrick picture Patrick · Jan 31, 2013 · Viewed 8.1k times · Source

I have the following ribbon.xml in my word vsto add-in:

<tab id="TabLetters" getVisible="IsLettersTabVisible" label="Letters">
 <group id="LettersGroup" label="Letters">
  <toggleButton id="NewWithTemplate"
              label="New using template Controls"
              size="large"
              imageMso="FileNew"
              onAction="NewTemplated" />
  </toggleButton>
 </group>
</tab>

And the following code behind the click event:

public void NewTemplated(Office.IRibbonControl control, bool value)
{
  CloseDocument();

  var doc = Globals.ThisAddIn.Application.Documents.Add(Template: @"LETTER_V2.dotx", Visible: true);
  doc.Activate();

  _ribbon.ActivateTab("TabLetters");
}

I would have expected this to result in a new window with my ribbon tab opened, however it just remains the HOME tab that is visible/current. How do I make it happen that my tab is the one that is visible?

Answer

Denys Wessels picture Denys Wessels · Feb 5, 2013

Here are two ways you can use to set the active tab:

TabLetters.RibbonUI.ActivateTab("TabLetters"); or

Globals.Ribbons.CustomRibbon.Tabs[Your tab id].RibbonUI.ActivateTab("TabLetters");