Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSTO Word activate ribbon tab

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?

like image 206
Patrick Avatar asked Jan 31 '13 14:01

Patrick


People also ask

How can you activate a tab or ribbon in MS Word?

Double-click any of the ribbon tabs or press CTRL+F1 to collapse the ribbon if you need to see more of your document. To see the ribbon again, just double-click any ribbon tab, or press CTRL+F1.

Is a ribbon tab available in MS Word?

The Ribbon is a user interface element which was introduced by Microsoft in Microsoft Office 2007. It is located below the Quick Access Toolbar and the Title Bar. It comprises seven tabs; Home, Insert, Page layout, References, Mailing, Review and View.

Where are the ribbons in Word?

In Microsoft Office applications, the Ribbon is the bar at the top of the window. It contains a variety of tools, organized by tabs, that help you edit and format a document. This page provides an overview of the options and tools on each tab of the Ribbon for Microsoft Word, Excel, and PowerPoint.


2 Answers

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");
like image 196
Denys Wessels Avatar answered Sep 22 '22 13:09

Denys Wessels


I found solution for excel 2007.

code :

int appVersion = Convert.ToInt32(Globals.ThisAddIn.Application.Version.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries)[0]);
if (appVersion >= 14 )            
{
    ThisRibbonCollection ribb = Globals.Ribbons;
    ribb.[Your Ribbon].ApplicationGroup.RibbonUI.ActivateTab("tab");                
}
else if(appVersion == 12)  // Specific to Office 2007 only.
{
                SendKeys.Send("%TAB%"); // use sendwait if you running it in thread.
}
like image 45
Hardik Shah Avatar answered Sep 20 '22 13:09

Hardik Shah