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
Solved

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

Posted on 2014-11-14
2
221 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Most folk recognise that Microsoft Excel, being a numbers-and-formulae-centric application attracts programmers due to the natural fit in mindset. Conversly, when opening Microsoft's dominant presentation creative application, few consider what…
Outline From PowerPoint 2010 it is possible to have shapes appear in front of video, in earlier versions video always played in front of other shapes. This means it is possible to have captions animated to appear in front of video. Users who h…
This video teaches viewers how to create handouts from their slides and helps them decide how many slides to include per handout.
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: …

856 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