title: How to make a loop in PowerPoint VBA?
body: <p>As far as I know, the code below gets a shape from the active window, nudges it a bit, copies the slide and pastes it right after the current one, then turns the pasted slide into an active window, and nudges it again:</p>
  
  <blockquote>
    <p>Sub Test()</p>
  
  <pre><code>' Get the active presentation
  
  Dim oPresentation As Presentation
  Set oPresentation = ActivePresentation
  
  ' Get the first slide in the presentation
  
  Dim oSlide As Slide
  Set oSlide = oPresentation.Slides(1)
  
  ' Get the first shape on the slide
  
  Dim oShape As Shape
  Set oShape = oSlide.Shapes(1)
  
  ' Nudge the shape to the right
  
  oShape.Left = oShape.Left + 1
  
  ' Copy the whole slide
  
  oSlide.Copy
  
  ' Paste the slide as a new slide at position 2
  
  Dim oNewSlides As SlideRange
  Set oNewSlides = oPresentation.Slides.Paste(2)
  
  ' Get a reference to the slide we pasted
  
  Dim oNewSlide As Slide
  Set oNewSlide = oNewSlides(1)
  
  ' Get the first shape on the NEW slide
  
  Dim oNewShape As Shape
  Set oNewShape = oNewSlide.Shapes(1)
  
  ' Nudge the shape to the right
  
  oNewShape.Left = oNewShape.Left + 1
  </code></pre>
    
    <p>End Sub</p>
  </blockquote>
  
  <p>As far as I can understand, in order to implement this code, I should have an active window opened and it should have at least one shape in it. Before I run this code I have only one slide; after the code has been run, I have two slides: the older one is number 1, and the newer one is number 2. </p>
  
  <p>If I run this code one more time, I will get three slides as a result: the oldest one being still number 1, but the oldest one being number 2, not number 3.</p>
  
  <p>My question is how can I make it produce slides, so that the newer slides are always the ones with a greater ordinal number, i.e. every newly created slide should be the last one in the slide preview sidebar (the lowest one)?</p>
  
  <p>And also, how can I make it into a loop? So that I don't need to re-run this code again and again, but simply make a loop with a given number of loop's iterations.</p>
  
  <p>I guess, if it should be a loop, then slides index should be turned into a variable, but I don't know how to do it in PowerPoint VBA. </p>