Answered by:
Is there a way to activate a certain Tab on the Ribbon?

Question
-
I have a Word 2007 application level add-in that creates a custom tab on the ribbon ("MyTab").
I would like to write code in the DocumentOpen to force "MyTab" to be the current active tab when certain documents are in use.
Is there a callback that will allow me to force a particular ribbon tab to be selected?
Thursday, December 28, 2006 7:44 PM
Answers
-
Unfortunately, the new ribbon model does not support the ability to programmatically set any control (control, group or tab) to be the active control. This is part of the design of the ribbon.
The main idea behind this aspect of the design is that the user should never be "surprised" by changes in the UI. They should always be in control of the ribbon, as far as possible, with the exception of certain built-in behaviors of the app itself. Add-ins are not allowed to take part in this behavior. In this way, the user always has a consistent experience when working with the ribbon UI.
Friday, March 16, 2007 1:17 AM
All replies
-
I would like to know this aswell. Got a button in my ribbon to open a template, and when the template opens, Word changes to the "home" tab. Would like to change back to my custom tab, but can't figure out how.Friday, January 5, 2007 8:47 AM
-
Same question for me. I have a program in VBA that manage some particular documents, and my special Tab offerts some functions designed for this kind of documents. Therfore, my special Tab should be activated each time a new document of this kind is opened for consultation. So, why Microsoft Team did it so difficult to activate tabs ?
For the moment, I use the vba function "SendKeys", but it is not very clean, et it does not always work :
assuming that the keytip for my special tab is "JB", then I created this code in my vba program :
Sub ActivateMyTab()
' Activate Word application to be sure keys will be send to the right application
Application.Activate
' Be sure that the application is ready to receive my keys
DoEvents
' Send 'Alt' key alone :
SendKeys "%", True
' Then send the keytip :
SendKeys "JB{ENTER}", True
End subFriday, January 12, 2007 10:04 AM -
Unfortunately, the new ribbon model does not support the ability to programmatically set any control (control, group or tab) to be the active control. This is part of the design of the ribbon.
The main idea behind this aspect of the design is that the user should never be "surprised" by changes in the UI. They should always be in control of the ribbon, as far as possible, with the exception of certain built-in behaviors of the app itself. Add-ins are not allowed to take part in this behavior. In this way, the user always has a consistent experience when working with the ribbon UI.
Friday, March 16, 2007 1:17 AM -
Please consider adding this ability in the next release. While I understand your reasoning perfectly, there is another perspective.
If I create a document-level customization that includes a specialized Ribbon tab, the users of that customized document may expect the specialized tab to be active by default when the document first opens (unless there is a remembered, "sticky", tab from the last time it was opened).
It is, IMHO, disconcerting to see Home when I really want "mytab" for a particular customization.
I think that your guideline is a good one in any case. However, please give the VSTO community the option to choose otherwise.
Thanks!
E. Alex Davis
Oracle
Friday, August 1, 2008 6:19 PM -
I agree with Andrew's comments but the rules don't always get followed as if you are in word and create a new table the tab will automatically set the newly added tabs TABLE TOOLS DESIGN which sort of breaks the rule by forcing the user down a User Interface path, now that is what we want access to and am sure if you forward this comment to the Office team they should become a little more consistent in their approach to these types of rule and not "Surprising" or letting designers design applications with the correct level of refinement and quality that we are capable of doing if empowered
Regards
Friday, August 1, 2008 9:44 PM -
In C# you can do it like this (in 2010 anyway not sure about 2008)
Set your RibbonTab's's ControlID Type to Custom then:
MyRibbon ribbon = (MyRibbon)Globals.Ribbons.GetRibbon(typeof(MyRibbon)); ribbon.ActivateTab(ribbon.Tabs[0].ControlId.ToString());
- Proposed as answer by HerbF Friday, July 5, 2013 6:30 PM
Thursday, December 9, 2010 1:25 AM -
Thanks BernyInFrance. This worked for me. In Word 2007 am using:
' Send 'Alt' key alone :
SendKeys "%", True
' Then send the keytip :
SendKeys "U{ENTER}", Trueto select the custom tab when the document opens. I was able to use Applicaiton.SendKeys"%U{ENTER}" in Excel without incident. I'm not sure why you can't send the keys together and why the Do Events would be crucial.
WHEELS
WHEELS
Tuesday, January 28, 2014 8:07 PM -
I also totaly agree with Andrew and Alex
My Word add in jumps away form my custom ribbon tab to the HOME tab when the user creates a new document from a button in my cusom ribbon. That is cofusing for the user.
So I have no way to correct this??
Microsoft say that the application should not confuse the user, by changing tibbon tabs automaticly, but they do it themselfs by changing from my cusom tab to HOME tab.
regards
Vidar Martinsen
--- VidarMa
Thursday, May 4, 2017 9:05 AM -
I found a Solution and a fix. So sorry for my frustration.
The soliuion is:
Globals.Ribbons.MyRibbonInstanceName.RibbonUI.ActivateTab("MyRibbonControlId");
regards
--- VidarMa
Thursday, May 4, 2017 11:15 AM -
Thanks for sharing. It helped me with my project. Great Find!Friday, November 30, 2018 10:06 PM