none
How does one set the Focus on a custom Tab in the Backstage View RRS feed

  • Question

  • PLATFORM: Office 2019 APPLICATION: Microsoft Word

    We have created a custom tab that appears in the Backstage View.

    However, we would like to set the focus on this tab when the Backstage View is opened. The tab appears exactly where we would like it and works correctly, but we would like it to be selected.

    WHAT I'VE TRIED
    (The code below returns an error saying that the value I provided is out of range)

    public void OnShow(object contextObject)
    {
    
    	try
    	{
    
    		this.ribbon.ActivateTab("OurCustomTab");
    	}
    	catch(Exception e )
    	{
    		MessageBox.Show(e.ToString());
    	}
    
    
    }

    CUSTOM XML

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <commands>
        <command idMso="FileSave" onAction="FileSaveOverride"/>
        <command idMso="FileSaveAs" onAction="FileSaveAsOverride"/>
      </commands>
    
      <backstage onShow="OnShow">
    
        <tab id="OurCustomTab" label="CUSTOM" insertBeforeMso="TabInfo" title="OUR TAB" tag ="OUR" getVisible="IsOURTabVisible" >
          <firstColumn>
    
            <group id="OURSave" label="Save" helperText="Performs Save operation for OUR documents">
              <primaryItem>
                <button id="OurCustomSaveButton" label="Save" imageMso="FileSave" isDefinitive="true" onAction="CustomSaveOverride" />
              </primaryItem>
            </group>
    
            <group id="OurSaveAs" label="Save As" helperText="Performs Save As operation for OUR documents">
              <primaryItem>
                <button id="OurCustomSaveAsButton" label="Save As" imageMso="FileSaveAs" isDefinitive="true" onAction="CustomSaveAsOverride" />
              </primaryItem>
            </group>
    
          </firstColumn>
        </tab>
    
    
      </backstage>
    </customUI>


    Germán Hayles



    • Edited by GermanEZI Wednesday, September 25, 2019 6:36 PM Clarification
    Wednesday, September 25, 2019 11:02 AM

Answers

  • It looks like **ActivateTab** will not work in this instance.

    Microsoft Active Accessibility and Microsoft UI Automation won't work here either.  It looks like the controls are not loaded at the time that the "OnShow" callback is called.

    How I tested this was by running a separate executable file that was able to set the focus on a custom tab in the Backstage View.  The identical code would not work within the VSTO Add-in.

    Since running an separate executable is outside the scope of our project I simply resorted to using SendKeys; not my favorite choice, but it works.



    Germán Hayles

    • Marked as answer by GermanEZI Monday, October 7, 2019 7:07 PM
    Monday, October 7, 2019 7:07 PM

All replies

  • It looks like the answer likes within the API "ActivateTab".   Now to find the "ControlId".   I'm not 100% sure on where this will be found.

    Germán Hayles

    Wednesday, September 25, 2019 2:56 PM
  • It looks like **ActivateTab** will not work in this instance.

    Microsoft Active Accessibility and Microsoft UI Automation won't work here either.  It looks like the controls are not loaded at the time that the "OnShow" callback is called.

    How I tested this was by running a separate executable file that was able to set the focus on a custom tab in the Backstage View.  The identical code would not work within the VSTO Add-in.

    Since running an separate executable is outside the scope of our project I simply resorted to using SendKeys; not my favorite choice, but it works.



    Germán Hayles

    • Marked as answer by GermanEZI Monday, October 7, 2019 7:07 PM
    Monday, October 7, 2019 7:07 PM