none
Delete object on slide by code in VSTO 2010? RRS feed

  • Question

  • Dear,

    How to deleted selected object on slide by code?

    Thx


    3D Interactive Simulations And Web Developer

    Friday, May 25, 2012 3:30 AM

Answers

  • Hi Hassan,

    Thanks for posting in the MSDN Forum.

    I suppose you use PowerPoint 2012, Visual Studio 2010 and C# to handle your issue.

    I create a Ribbon button to reproduec your issue. Following is the snippet, it works fine on my side.

    using PowerPoint = Microsoft.Office.Interop.PowerPoint;
    
    namespace PowerPointAddIn10
    {
        public partial class Ribbon1
        {
            private ILog Log = MyLog4Net.MyLog4Net.GetMyLog(typeof(Ribbon1));
    
            private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
            {
    
            }
    
            private void button1_Click(object sender, RibbonControlEventArgs e)
            {
                try
                {
                    PowerPoint.Application ppApp = Globals.ThisAddIn.Application;
                    Log.Info("Get PowerPoint Application instance");
                    PowerPoint.Presentation ppP = ppApp.ActivePresentation;
                    Log.Info("Get Active Presentation");
                    PowerPoint.Slide ppS = ppP.Slides[1];
                    Log.Info("Get First Slide");
                    for (int i = ppS.Shapes.Count; i > 0; i--)
                    {
                        PowerPoint.Shape sp = ppS.Shapes[i];
                        string name = sp.Name;
                        sp.Delete();
                        Log.Info(name + " has been deleted");
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
                }
            }
        }
    }

    I hope it can help you.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Hassan Ayoub Tuesday, May 29, 2012 11:49 AM
    Monday, May 28, 2012 6:53 AM
    Moderator

All replies

  • Hi Hassan,

    Thanks for posting in the MSDN Forum.

    I suppose you use PowerPoint 2012, Visual Studio 2010 and C# to handle your issue.

    I create a Ribbon button to reproduec your issue. Following is the snippet, it works fine on my side.

    using PowerPoint = Microsoft.Office.Interop.PowerPoint;
    
    namespace PowerPointAddIn10
    {
        public partial class Ribbon1
        {
            private ILog Log = MyLog4Net.MyLog4Net.GetMyLog(typeof(Ribbon1));
    
            private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
            {
    
            }
    
            private void button1_Click(object sender, RibbonControlEventArgs e)
            {
                try
                {
                    PowerPoint.Application ppApp = Globals.ThisAddIn.Application;
                    Log.Info("Get PowerPoint Application instance");
                    PowerPoint.Presentation ppP = ppApp.ActivePresentation;
                    Log.Info("Get Active Presentation");
                    PowerPoint.Slide ppS = ppP.Slides[1];
                    Log.Info("Get First Slide");
                    for (int i = ppS.Shapes.Count; i > 0; i--)
                    {
                        PowerPoint.Shape sp = ppS.Shapes[i];
                        string name = sp.Name;
                        sp.Delete();
                        Log.Info(name + " has been deleted");
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(string.Format("{0}\n{1}", ex.Message, ex.StackTrace));
                }
            }
        }
    }

    I hope it can help you.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Hassan Ayoub Tuesday, May 29, 2012 11:49 AM
    Monday, May 28, 2012 6:53 AM
    Moderator
  • Thx, but how can i delete an object selected by mouse?

    3D Interactive Simulations And Web Developer

    Tuesday, May 29, 2012 12:41 AM
  • Hi Hassan,

    This is a new issue, I would recommend you post a new thread for the issue "delete an object selected by mouse". It will make threads more clear for the goal and community member will easy to retieve it if you do it.

    I hope I can reply your issue in a new thread. And would you please mark this thread if you feel it solved your first aim?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, May 29, 2012 7:20 AM
    Moderator