VSTO Word Activates Ribbon Tab

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

<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 after 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 expect this to lead to the appearance of a new window with the ribbon tab open, however it will only remain on the HOME tab, which is visible / current. How to make my tab visible?

+5
source share
5 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");
+4
source

I found a solution for excel 2007.

the 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.
}
+2
source

Excel 2013 , :

try
{
    //  Attempt to set the my VSTO ribbon bar as the active ribbon.
    string controlID = Globals.Ribbons.GetRibbon<MikesRibbon>().MikesTab.ControlId.ToString();
    this.RibbonUI.ActivateTab(controlID);
}
catch
{
}

, , ControlID ActivateTab.

MikesRibbon.cs ( !) VS2013. , , FILE .

"" "" (.. FILE), "" ControlID, .

+1

, Office 2007 (, ). ( , ) Office 2007:

  • ALT, .
  • In your code, you can send these keys using the SendKeys.SendWait function

Hope this helps someone. Regards, Jörg


the code:

    public void FocusMyCustomRibbonTab()
    {
        if (IsExcel2007())
        {
            Globals.Ribbons.GetRibbon<MyRibbon>().tabMyRibbonTab.KeyTip = "GGG";

            //Excel 2007: Must send "ALT" key combination to activate tab, here "GGG"
            SendKeys.Send("%");                       
            SendKeys.Send("{G}");                     
            SendKeys.Send("{G}");                     
            SendKeys.Send("{G}");                     
            SendKeys.Send("%");                       
        }
        else
        {
            //Excel 2010 or higher: Build in way to activate tab
            if (this.ribbon.RibbonUI != null)
            {
                this.ribbon.RibbonUI.ActivateTab("MY_RIBBON_TAB_NAME");
            }
        }
    }

    public static bool IsExcel2007()
    {
        return (Globals.ThisAddIn.Application.Version.StartsWith("12"));
    }
0
source

In Word 2016, use RibbonUI.ActivateTabMso (controlID) to activate the general tabs of the word ribbon.

In addition, you can get the correct feed link by adding to your AddIn:

static internal Microsoft.Office.Tools.Ribbon.OfficeRibbon rUI = null;


private void WorkBenchRibbon_Load(object sender, Microsoft.Office.Tools.Ribbon.RibbonUIEventArgs e)
    {
        rUI = ((Microsoft.Office.Tools.Ribbon.OfficeRibbon)sender).Ribbon;
    }
0
source

All Articles