Trouble looping through PowerPoint slides in ActivePresentation if I delete along the way
Posted on 2014-11-14
In my macro, I gather parameters for types of slides to keep, then I want to iterate through a deck of 123 slides and keep only those that match the parameters.
So I'm going through and deleting slides that don't match the parameters. I know I can't do from slide = 1 to activepresentation.slides.count, because then if you delete any along the way, you'll eventually get beyond the original count. I tried the old reverse loop from activepresentation.slides.count to 1 step =1, but same thing happens when I delete a slide, it skips slides. Appears that the slide index numbering shifts each time the number of slides changes. I've tried for each myslide in activepresentation.slides, but same thing happens. The act of deleting a slide messes up whatever pointer is being used.
I want to make sure I examine every slide, but not sure how to do that. Maybe go through every slide, building an array of slide titles to be deleted, then delete them all at the end of the iteration? There must be a more elegant solution.
Appreciate any help.