Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Accessing the Ribbon at Run Time

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Excel 2007

  • Word 2007

  • Outlook 2007

  • PowerPoint 2007

For more information, see Features Available by Application and Project Type.

You can write code to show, hide, and modify the Ribbon, and enable users to run the code from controls in a custom task pane, actions pane, or Outlook form region.

You can access the Ribbon by using the Globals class. For Outlook projects, you can access the Ribbons that appear in specific Outlook Inspector windows.

You can use the Globals class to access the Ribbon in a document-level project or application-level project from anywhere in the project.

For more information about the Globals class, see Global Access to Objects in Visual Studio Tools for Office Projects.

The following example uses the Globals class to access a custom Ribbon named Ribbon1 and set the text that appears on a combo box on the Ribbon to Hello World.

private void Access_All_Ribbons_Globals()
{
    Globals.Ribbons.Ribbon1.comboBox1.Text = "Hello World";
}

You can access a collection of Ribbons that appear in Outlook Inspectors. An Inspector is a window that opens in Outlook when users perform certain tasks, such as creating e-mail messages. To access the Ribbon of an Inspector window, call the Ribbons property of the Globals class and pass in an Inspector object that represents the Inspector.

The following example gets the Ribbon collection of the Inspector that currently has focus. This example then accesses a Ribbon named Ribbon1 and sets the text that appears on a combo box on the Ribbon to Hello World.

private void Access_Ribbons_By_Inspector()
{
    ThisRibbonCollection ribbonCollection = 
        Globals.Ribbons
            [Globals.ThisAddIn.Application.ActiveInspector()];
    ribbonCollection.Ribbon1.comboBox1.Text = "Hello World";
}
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2015 Microsoft