PDA

View Full Version : [SOLVED] power point error adding shapes



Bennettd02
11-20-2007, 02:50 AM
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

John Wilson
11-20-2007, 04:01 AM
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?

Bennettd02
11-20-2007, 04:20 AM
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

John Wilson
11-20-2007, 04:56 AM
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!