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
Microsoft Office version
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.
Accessing the Ribbon by Using the Globals Class
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 Sub Access_All_Ribbons_Globals()
Globals.Ribbons.Ribbon1.comboBox1.Text = "Hello World"
End Sub
private void Access_All_Ribbons_Globals()
{
Globals.Ribbons.Ribbon1.comboBox1.Text = "Hello World";
}
Accessing a Collection of Ribbons in Outlook
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 Sub Access_Ribbons_By_Inspector()
Dim ribbonCollection As ThisRibbonCollection = Globals.Ribbons _
(Globals.ThisAddIn.Application.ActiveInspector())
ribbonCollection.Ribbon1.ComboBox1.Text = "Hello World"
End Sub
private void Access_Ribbons_By_Inspector()
{
ThisRibbonCollection ribbonCollection =
Globals.Ribbons
[Globals.ThisAddIn.Application.ActiveInspector()];
ribbonCollection.Ribbon1.comboBox1.Text = "Hello World";
}
See Also
Tasks
Walkthrough: Creating a Custom Tab by Using the Ribbon Designer
Walkthrough: Updating the Controls on a Ribbon at Run Time