I want to delete a Text Box with a certain Text in PowerPoint 2010 and encountered a weird problem.
The code works fine if the slide has NO PICTURES on it. However, if there is a picture on the slide im getting an error message:
"Runtime error -2147024809 (80070057)
Given Value is out of bounds" (translated so might not be exact)
Here is my code:
Sub delete()
Dim SlideToCheck As Slide
Dim ShapeIndex As Integer
' Visit each slide
For Each SlideToCheck In ActivePresentation.Slides
' On each slide, count down through the shapes
For ShapeIndex = SlideToCheck.Shapes.Count To 1 Step -1
' If the shape IS a text box and has text (...)
If SlideToCheck.Shapes(ShapeIndex).Type = msoTextBox And _
SlideToCheck.Shapes(ShapeIndex).TextFrame.TextRange.Text = ("sample text") Then
' Delete the shape
SlideToCheck.Shapes(ShapeIndex).TextFrame.DeleteText
End If
Next
Next
End Sub
Like I said, the code works 100% fine without pictures.
Hope someone can help,
Thanks