2012-03-22 8 views
1

ここでは誰かが助けてくれることを願っています。私は1つのパワーポイントプレゼンテーションから次のプレゼンテーションにスライドをコピーアンドペーストしようとしています。私はそれをコピーしてすべてのスライドを正しいものにコピーして貼り付けるようにしていますが、私の問題はプレゼンテーションの最後のスライドを何度も貼り付けていることです。私は/ foreachループの両方を試してきましたが、まだ私に1つのスライドを与えています、私はCommandBarsではないかと思います。しかし、私はfor/foreachループでスライドをリセットするためにそれらが使用されていることがわかります。何か案は?C#VSTO-PowerPointソースの書式設定によるスライドのコピー/ペースト

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 < 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); 
     } 

    } 

答えて

2

PasteSourceFormattingの後にPPTを保存してみてください。私は同じ問題を抱えていました。

+0

問題を修正しました。 – KJones

1

PasteSourceFormattingの後にApplication.DoEvents()を使用しました。正常に動作しました。

関連する問題