Solved

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

Posted on 2014-11-14
2
218 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
ID: 40442159
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
ID: 40442197
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been sent a PowerPoint presentation file and wondered why it filled your mailbox? Or have you ever sent a PowerPoint presentation by email and received complaints about the size? Or have you ever created a PowerPoint presentation and t…
 Regular Expressions Microsoft Word has sophisticated search tools that can search for patterns. For example if you wanted to search for all UK phone numbers that followed a pattern of five digits, a space and then six digits you can easily do th…
This video teaches viewers how to add simple and professional themes to their slides.
This video teaches viewers how to create handouts from their slides and helps them decide how many slides to include per handout.

815 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

9 Experts available now in Live!

Get 1:1 Help Now