|PowerPoint tips, hints and tutorials that will change your presentations for ever!|
Delete Shapes with vba
If you have a little vba knowledge deleting certain shapes from a slide may seem fairly simple. Imagine we are looking for shapes with a 6 point line.
'READ ON THIS DOESN'T WORK
Looks like it will loop through all the shapes and delete any with a 6 point line.
BUT it won't
Imagine there are 6 shapes and 4 & 5 have this line. When it gets to shape 4 it will be deleted. At this point though what was shape 5 will become shape 4. THe vba will jump this shape and test the old shape 6 (now shape 5). Next it will look for shape 6 which no longer exists! PowerPoint is now going to say whoa wheres six = CRASH!
Read that again and when you have your head round it look at:
'READ ON THIS DOESN'T WORK EITHER
This looks promising and will usually work. Sometimes though it will seem to randomly fail to delete shapes which should go!
PowerPoint is smart enough to notice there are fewer shapes in the shape collection but can still miss out shapes if there are consequtive match shapes. In the example above only 1,2,3,4 & 6 are checked. As long as 5 is not a match you're good. If it is a match though ....
Loop BACKWARDS through the shapes this way if shape 5 is deleted shape 4 still exists!
Free Microsoft PowerPoint Advice, help and tutorials, Template Links