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?
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.
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.
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.
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");
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.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With