Solved

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

Posted on 2014-11-14
2
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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.…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This video teaches viewers how to add simple and professional themes to their slides.
This video teaches viewers how to add transitions to their Slideshows and how to set up timing for the transitions.

726 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