PDA

View Full Version : Active selection default after delete



hewillaugh
09-19-2010, 05:04 PM
I am looking to delete all the Pictures on a slide and I have them being processed through a loop.


Dim oPres as ActivePresentation
Dim oShape as Shape
Dim oShapes as Shapes

Set oPres = ActivePresentation
For Each oShape In oShapes
reCheck:
If oShape.Type = 13 Then
oShape.Delete
GoTo reCheck
End If
Next oShape

Before I added the GoTo reCheck, sometimes after deleting a Picture, it would skip deleting a picture and delete the next. My assumption was that after a shape was deleted, oShape would default to the next shape.

After a shape is deleted, by default what is the active selection? Is there a cleaner / tighter way to do this?

Thanks in advance for your help!

John Wilson
09-20-2010, 12:28 AM
When you delete any shape you must step BACKWARDS through the shapes. This is because if say you delete shape 2, shape 3 becomes the new shape 2 BUT shape 2 is already processed....

Sub delete_allpics()
Dim osld As Slide
Dim i As Integer
For Each osld In ActivePresentation.Slides
For i = osld.Shapes.Count To 1 Step -1
If osld.Shapes(i).Type = msoPicture Then osld.Shapes(i).Delete
Next i
Next osld
End Sub

Sub delete_currentslidepics()
Dim osld As Slide
Dim i As Integer
Set osld = ActiveWindow.View.Slide
For i = osld.Shapes.Count To 1 Step -1
If osld.Shapes(i).Type = msoPicture Then osld.Shapes(i).Delete
Next i
End Sub

John Wilson
09-20-2010, 03:29 AM
I should have mentioned I don't believe your original code will even run as it stands!