Question

Is it possible from the Powerpoint slide, I can access to a Ribbon menu item? For example, I have a checkbox under the Ribbon Menu. Now I want that when I click a shape, this checkbox should be checked?

The issue seems to be easy, but I cannot find a way to do it. Do you have any idea? (prefer in C#)

enter image description here

EDITED with CODE

The custom ribbon menu

public partial class RibbonMenu
{
        private void RibbonMenu_Load(object sender, RibbonUIEventArgs e)
        {

        }

        public void ChangeCheckBox()
        {
              System.Windows.Forms.MessageBox.Show("The CheckBox is changed");
              this.checkBox.Checked = true;
              this.checkBox.Label = "AAAAAAA"
        }

}

Catch the selection event

public partial class ThisAddIn
{
        private RibbonMenu menu;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            CreateRibbonExtensibilityObject();
            Application.WindowSelectionChange   += new PowerPoint.EApplication_WindowSelectionChangeEventHandler(Application_WindowSelectionChange);

        }

        protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
        {
            this.menu = new RibbonMenu();

            return Globals.Factory.GetRibbonFactory().CreateRibbonManager(new Microsoft.Office.Tools.Ribbon.IRibbonExtension[]
             {
                  this.menu                  
             });
        }

        private void Application_WindowSelectionChange(PowerPoint.Selection Sel)
        {
            //.... Check if the selection is a shape's selection
            this.menu.ChangeCheckBox();         
        }
}

The Result is the message box "The CheckBox is changed"" is appeared, but the checkbox is not cheched and the label is not changed to "AAAAAA"

Was it helpful?

Solution

Using Globals to access the Office Ribbon Menu Item as follow:

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

OTHER TIPS

I think you have to use the Application.WindowSelectionChange event for this.

According to MSDN:

Occurs when the selection of text, a shape, or a slide in the active document window changes, whether in the user interface or in code.

It will give you a Selection object which you can use further on.

Signature of the event handler:

void (Microsoft.Office.Interop.PowerPoint.Selection selection)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top