none
the index into specified collection is out of bounds (powerpoint) RRS feed

  • Question

  • i have a problem with powerpoint footer (powerpoint 2003)

    my code:

    for (int x = 1; x <= pst.Application.ActivePresentation.Slides.Count; x++)
    {
                        pst.Slides[x].HeadersFooters.Footer.Visible = Office.MsoTriState.msoTrue;
                        Microsoft.Office.Interop.PowerPoint.Slide slide = pst.Slides[x];
                        Microsoft.Office.Interop.PowerPoint.Shape shap = slide.Shapes[3];                   
                            if (shap.HasTextFrame == Office.MsoTriState.msoTrue)                       
                                    shap.TextFrame.TextRange.Text = "ABC";

    }

    show error:

    the index into specified collection is out of bounds

    whereas when tested in office 2007 does not matter

     

    Monday, April 11, 2011 3:27 AM

Answers

  • Hi Yan

    Rather than use a specific index - Shapes[3] - if you need the last Shape, get the number of Shapes dynamically?

      int nrShapes = slide.Shapes.Count;
      Microsoft.Office.Interop.PowerPoint.Shape shap = slide.Shapes[nrShapes];


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Yan2010 Wednesday, April 13, 2011 8:30 AM
    Tuesday, April 12, 2011 6:12 AM
    Moderator

All replies

  • HI Yan,

     

    are there 3 Shapes in Slide.Shapes?

    Greets - Helmut


    Helmut Obertanner [http://www.x4u.de] [http://www.outlooksharp.de]
    Monday, April 11, 2011 5:34 AM
    Answerer
  • no is only two, but in powerpoint 2007 the third shape will be formed by itself when the application runs, but in powerpoint 2003 difference, how to form a shape?
    Monday, April 11, 2011 6:09 AM
  • Hi Yan

    Rather than use a specific index - Shapes[3] - if you need the last Shape, get the number of Shapes dynamically?

      int nrShapes = slide.Shapes.Count;
      Microsoft.Office.Interop.PowerPoint.Shape shap = slide.Shapes[nrShapes];


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Yan2010 Wednesday, April 13, 2011 8:30 AM
    Tuesday, April 12, 2011 6:12 AM
    Moderator