Consulting

Results 1 to 4 of 4

Thread: power point error adding shapes

  1. #1

    power point error adding shapes

    I get the following error when trying to add a shape -

    The index into the specified collection is out of bounds

    My Code--

    Set ppObj = New PowerPoint.Application
    Set ppPres = ppObj.Presentations.Open("P:\Default\Slide Master.ppt")
    'Set ppPres = ppObj.Presentations.Add
    i = 1
    ' Setup the set of slides and populate them with data from the
    ' set of records.
    With ppPres
        While Not rsSlide.EOF
            With .Slides.Add(rsSlide.AbsolutePosition, ppLayoutTitle)
                .Shapes(1).TextFrame.TextRange.Text = rsSlide("Title")
                i = i + 1
                While Not rsContent.EOF
                    .Shapes(i).TextFrame.TextRange.Text = rsContent("Text").Value
                    .Shapes(i).TextFrame.TextRange.Characters.Font.Color.RGB = RGB(255, 0, 255)
                    rsContent.MoveNext
                    i = i + 1
                Wend
                rsContent.MoveFirst
            End With
            rsSlide.MoveNext
        Wend
    -The error appears to happen when ever i try to add a shape object of 3 or higher, would anyone one be able to point out where i am going wrong
    Last edited by Aussiebear; 04-28-2023 at 08:08 PM. Reason: Adjusted the code tags

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Hi

    As far as I can tell you're not adding any shapes to the slides you create. Layout ppLayoutTitle has two shapes "built in" which is why Shapes(3) errors.

    Not sure whether you are trying to add more text to Shapes(2) or a new textbox?
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    Ahhh I see!, will post will post correct code when done, thanks John, ps. i was trying to add a new textbox, i made the error of assuming that just specifying a shape index would add it to the shape array or something along those lines, as you can tell im a bit of a newbie,

    thanks again

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    No Problem. Maybe this will help set you off...

    Sub test()
    Dim osld As Slide
    Dim oshp As Shape
    Set osld = ActivePresentation.Slides.Add(1, ppLayoutText)
    Set oshp = osld.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 10, 200, 50)
    With oshp.TextFrame.TextRange
        .Text = "This is a sample"
        .Font.Name = "Arial"
        .Font.Size = 24
        .Font.Color.RGB = RGB(100, 255, 255)
    End With
    End Sub
    You should use the vba tags here - they help!
    Last edited by Aussiebear; 04-28-2023 at 08:09 PM. Reason: Adjusted the code tags
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •