Adding a ActiveX Plugin to Powerpoint without using the Developer Tab RRS feed

  • Question

  • Currently, in order to add our ActiveX plugin, users need to go to the Developer Tab, click "More Controls", select the ActiveX plugin, then draw it into a Powerpoint slide.  I want to create a Ribbon that has a button that does the same thing without requiring users to add the Developer Tab.

    In order to do this, I have created a Ribbon with a Button that should do the same thing.  I get close to the right behavior, but I cannot find the correct callbacks in Powerpoint to get it right.

    To do this, the action of the button:

    - checks whether the "ShapeRectangle" MSO is enabled
      - if its enabled, unselect everything, execute the "Shape Rectangle", and set a ribbon-level
        boolean variable that keeps track of whether this button has been pressed
      - if its not enabled, show a message box that says that this function is not available
    code for this action is like this:

    private void addActiveX_Click(object sender, RibbonControlEventArgs e)
        PowerPoint.Application pptApp = new PowerPoint.Application();
        if (pptApp.CommandBars.GetEnabledMso("ShapeRectangle"))
            ThisAddIn.should_change_on_selection_change = true;
            System.Windows.Forms.MessageBox.Show("Creating ActiveX not enabled, please select a slide", "ActiveX Plugin");

    We then override the WindowSelectionChange event in the AddIn like this in InternalStartup():

    this.Application.WindowSelectionChange += new PowerPoint.EApplication_WindowSelectionChangeEventHandler(selectionChanged);

    Where in the selection change callback, we :

    - check the boolean variable to see if the button has been checked
    - check to see if the selection has one object, is the last object on the active slide, and the name starts with "Rectangle"
    - if it does fit these criteria, then we add the ActiveX Component, delete the selection, and select the new ActiveX Object

    Code for the selection change callback is like this:
    void selectionChanged(PowerPoint.Selection Sel)
        PowerPoint.Application pptApp = new PowerPoint.Application();
        PowerPoint.DocumentWindow aw = pptApp.ActiveWindow;
        PowerPoint.Presentation ap = pptApp.ActivePresentation;
        PowerPoint.Slide slide = ap.Slides[aw.View.Slide.SlideIndex];
        if (should_change_on_selection_change && Sel.ShapeRange.Count == 1 && Sel.ShapeRange.Name.StartsWith("Rectangle") &&
            slide.Shapes.AddOLEObject(Sel.ShapeRange.Left, Sel.ShapeRange.Top, Sel.ShapeRange.Width, Sel.ShapeRange.Height, "<ActiveX ID>");
        should_change_on_selection_change = false;

    This is a major hack, but only has some minor drawbacks.  However, since this is such a common task that developers might want to provide, I would think that there is a better way to implement this.  But I can't seem to find the callbacks necessary to do this in Powerpoint.

    Some of the Drawbacks/Questions:

    - Can I create a new MSO action that does something very similar to ShapeRectangle, but create an object that has a different prefix string?  This way I could check for that string in the selection change callback.  Or better yet, generate an object with an ActiveX type?  It would be even better to be able to specify an image that is shown as the user draws out the new object, but that might be asking a lot.
    - Is there a callback for new objects?  This would make sense, instead of overriding selection changes, which is error-prone.
    - There are times where the "ShapeRectangle" action is not available (e.g., when you select below the last slide in the thumbnail pane), and we are forced to show a message box when this happens.  However, we would rather disable our button on our Add-In as well.  I have tried to add other callbacks, and set our button to Enabled if "ShapeRectangle" exists, but this doesn't work.  Is there a way to determine when these actions are enabled/disabled (i.e., is there a callback?), and change our AddIn button to mimic the same?

    Thanks in advance,


    • Moved by Max Meng Thursday, April 25, 2013 7:09 AM
    Wednesday, April 24, 2013 9:31 PM

All replies

  • are you working on ribbon xml ribbon?

    >Can I create a new MSO action that does something very similar to ShapeRectangle, but create an object that has a different prefix string?

    I don't think so.

    with regards, Yuri

    Monday, April 29, 2013 2:35 PM