locked
How do I get the selected picture in PowerPoint? RRS feed

  • Question

  • This is using the COM (not VSTO) API from my AddIn to PowerPoint.

    I have selected a picture. I then do the following:

    Selection selection = presentation.Application.ActiveWindow.Selection;
    Slide slide = selection.SlideRange[selection.SlideRange.SlideIndex];
    // slide.Shapes[2] is the selected picture
    

    How do I know to get [2] instead of [1]? The [1] is a textbox that is on the slide, but is not selected.

    thanks - dave


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Sunday, December 2, 2018 12:04 AM

All replies

  • Hi David,

    For most slide layouts, the first shapes on the slide are text placeholders. Please refer to the following link:

    Slide.Shapes Property (PowerPoint)

    You could test the properties of [1] and [2] to determine what they really are.

    Hopefully it helps you.

    Best Regards,

    Bruce


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Monday, December 3, 2018 10:05 AM
  • Hi Bruce;

    My concern with using a set index is that they might be something else. I need to know with certainty what is the selected object. And I don't even know what type it is as the user is selecting the object, so I can't test by type.

    What/how can I get the selected object?

    thanks - dave


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Monday, December 3, 2018 2:28 PM
  • Hi David,

    You could use the Shape.Type property to determine the object type.

    <<What/how can I get the selected object?

    You can use Windows (index). Selection.ShapeRange gets all the shape, then uses the index or uses the loop to get each shape.

    You could refer to the following links:

    Selection Object (PowerPoint)

    Shape.Type Property (PowerPoint)

    Best Regards,

    Bruce


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.





    Tuesday, December 4, 2018 7:41 AM
  • Hi Bruce;

    The problem is I don't know the type either. When the user selects an object my AddIn code then needs to perform actions based on that object. So step one is to determine the selected object.

    How can we determine what object is presently selected?

    thanks - dave


    What we did for the last 6 months - Made the world's coolest reporting & docgen system even more amazing

    Tuesday, December 4, 2018 1:09 PM