Answered by:
Call Custom Backstage Tab From Ribbon Button

Question
-
I have a custom backstage view tab called "BR Print" and a custom button in the Print Preview tab ribbon.
I would like to be able to display the custom "BR Print" backstage view tab by clicking on my custom button. Does anyone have any idea how to do this?
Any help would be much appreciated!
Louis
Friday, April 27, 2012 3:33 PM
Answers
-
Hi Louis
I believe the only simple way is to use SendKeys to mimic the user pressing Alt+F followed by the keyboard shortcut for your Ribbon tab.
As always with SendKeys, it's not guaranteed to always work, or to always work the way you intend. For example, if your code is executing in a non-English interface a different letter than "F" may be assigned to the main backstage (File) menu. Or Word may change the key assignment you define for the button in your Ribbon XML because it conflicts with another key assignment.
The less simple approach would be to use the Ribbon Accessibility APIs:
- Blog article on which that bases: http://blogs.msdn.com/pranavwagh/archive/2008/01/21/how-to-switch-ribbon-tab-programmatically-looks-simple.aspx
- MSDN documentation: http://msdn.microsoft.com/en-us/library/bb404170.aspx
- Code sample: http://code.msdn.microsoft.com/CSOfficeRibbonAccessibility-cd7fe67f
Cindy Meister, VSTO/Word MVP
Sunday, April 29, 2012 5:56 AM
All replies
-
Hi Louis
I believe the only simple way is to use SendKeys to mimic the user pressing Alt+F followed by the keyboard shortcut for your Ribbon tab.
As always with SendKeys, it's not guaranteed to always work, or to always work the way you intend. For example, if your code is executing in a non-English interface a different letter than "F" may be assigned to the main backstage (File) menu. Or Word may change the key assignment you define for the button in your Ribbon XML because it conflicts with another key assignment.
The less simple approach would be to use the Ribbon Accessibility APIs:
- Blog article on which that bases: http://blogs.msdn.com/pranavwagh/archive/2008/01/21/how-to-switch-ribbon-tab-programmatically-looks-simple.aspx
- MSDN documentation: http://msdn.microsoft.com/en-us/library/bb404170.aspx
- Code sample: http://code.msdn.microsoft.com/CSOfficeRibbonAccessibility-cd7fe67f
Cindy Meister, VSTO/Word MVP
Sunday, April 29, 2012 5:56 AM -
I decided to use the SendKeys option but have not had much success in getting it to work. In my XML, I have assigned a keytip ("BR6") my custom backstage view tab "BRPrint" (please see part of my code below)
<backstage>
<tab id="brPrint" label="BR Print" keytip="BP6" insertBeforeMso="TabPrint" columnWidthPercent="25" >
I then added an onAction callback to the "returnToBRPrint" method (shown below) which I cannot get to work. I initially thought that it was not working because I did not specifically identify which application or window should be in focus so tried to use "AppActivate "Microsoft Word" " which did not work either. Im aware that the post above stated SendKeys was unreliable but am I missing something? Just to note that I'm using Windows 7 as im aware that there was a bug with SendKeys using Vista.Has anyone got an idea on how I can solve this problem?
Any help would be appreciated.
Louis
<!-- XML for custom button -->
<button id="btnBRPrint" label="BR Print" size="large" imageMso="FilePrint" onAction="BRPrinting.returnToBRPrint" />
-----------------------------------------------------------------------------
Sub returnToBRPrint(control As IRibbonControl)
'Returns to the BR Print tab
SendKeys "%{F}"
SendKeys "%{BP6}" 'This line errors - Invalid procedure call or argument (even with this line commented out, it still doesn't navigate to the File tab)End Sub
Tuesday, May 1, 2012 11:37 AM