title: C# VSTO-PowerPoint Copy/Paste Slides with Source Formatting
body: <p>Quick question hopefully someone can help out here. I'm trying to copy and paste slides from one powerpoint presentation to the next. I've got it currently so that it will copy and paste all the number of slides over to the correct one, but my problem is it is only pasting over the last slide of the presentation over and over. I've tried both for/foreach loops, and yet is just give me the one slide, I'm wondering if it isn't the CommandBars. But I see them being used to reset slides in a for/foreach loop. Any ideas?</p>
  
  <pre><code>    public void AppendPPTX(string newContent)
      {
          int sourceSlideRange = 0;
          int targetSlideRange = Application.ActiveWindow.Presentation.Slides.Count;
          PowerPoint.Presentation target;
          PowerPoint.Presentation source;
  
          try
          {
              target = Application.ActivePresentation;
              source = Application.Presentations.Open(newContent, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse, Office.MsoTriState.msoFalse);
  
              sourceSlideRange = source.Slides.Count + 1; //otherwise I was just getting the second to the last slide
  
              for (int i = 1; i &lt; sourceSlideRange; i++)
              {
                  source.Slides[i].Copy();
                  target.Slides[targetSlideRange].Select();
                  target.Application.CommandBars.ExecuteMso("PasteSourceFormatting");
              }
              source.Close();
          }
          catch (Exception)
          {
              MessageBox.Show("Error opening PowerPoint, corruption found inside the powerpoint file. " +
                              Environment.NewLine + "The corrupted file has been deleted." + Environment.NewLine +
                              "Please attempt to redownload file.",
                              "Error Opening PowerPoint",
                              MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
  
      }
  </code></pre>