Solved

Trouble looping through PowerPoint slides in ActivePresentation if I delete along the way

Posted on 2014-11-14
2
209 Views
Last Modified: 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.
0
Comment
Question by:versatilebb
2 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
Comment Utility
for i = activepresentation.slides.count to 1 step -1 (I assume you meant "-1", not "=1") should work. I've done that before.

Could you post your code, and maybe a sample PowerPoint presentation.
0
 

Author Closing Comment

by:versatilebb
Comment Utility
Phillip:

Yes I did mean -1.  I just tried it again and it works.  So I must have been doing something wrong.

Thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction I recently received a question about the creation of Computer-Based Training (CBT) that incorporates quizzes in the middle of the lesson. The intent was to keep people engaged in the content, and not to actually track students’ scores.…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This video teaches viewers how to add transitions to their Slideshows and how to set up timing for the transitions.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now