Get selected chart object or text frame or table using C# VSTO addon?

463 Views Asked by At

I was trying to get a current selected object present in PPTX file for an VSTO addon.

I was using the below package for creating a chart,tables and text in slides.

using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Office = Microsoft.Office.Core;

I have a button present in the Ribben bar. Once the user clicks it I wanted to get the current selected object in any slide. How do I do this? Is there any way present in the interop package.

1

There are 1 best solutions below

0
On

If you are selecting one or more shapes, you could do something like this

if (Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange.Count > 0)
                {
                    //iterate over all the shapes selected by the user
                    foreach (PowerPoint.Shape shp in Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange)
                    {
                        if (shp.HasTable == Office.MsoTriState.msoTrue)
                        {
                            //Do something
                        }
                        if (shp.HasChart == Office.MsoTriState.msoTrue)
                        {
                            //Do something
                        }
                        if (shp.HasTextFrame == Office.MsoTriState.msoTrue)
                        {
                            //Do something
                        }

                        //or you could just return the shp object
                    }
                }