none
C# - Controlling PowerPoint Externally

    Question

  • Is it possible to modify a PowerPoint slideshow (insert slides, delete slides, etc.) while the slideshow is running?

    I need to continuously display a series of slides while at the same time being able to modify the slide list to accommodate new slides and delete outdated slides. Can this be controlled from an external program (C#) without stopping and restarting the slideshow?


    • Edited by CaptnCliff Monday, November 12, 2012 6:58 PM
    Monday, November 12, 2012 6:58 PM

Answers

  • Hi CaptnCliff,

    Thank you for posting in the MSDN Forum.

    According to your descritpion, I've written the code below. It's an Console Application.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using PowerPoint = Microsoft.Office.Interop.PowerPoint;
    using Office = Microsoft.Office.Core;
    using System.Threading;
    
    namespace ConsoleApplication_ModPresWhilePlaying
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Suppose you have a ppt file named SlidesCollection.pptx in D:\
                //I've create one with 3 slides, 1 slide with title One.
                //2nd slide with title Two. 3rd slide with title Four.
                string presExisting = @"D:\SlidesCollection.pptx";
                //Meanwhile you have a SingleSlide.pptx and you want to add into SlidesCollection.pptx
                //This single slide with title Three.
                string presToAdd = @"D:\SingleSlide.pptx";
    
                PowerPoint._Application pApp = new PowerPoint.Application();
                PowerPoint.Presentation pPre = pApp.Presentations.Open(
                    presExisting, Office.MsoTriState.msoFalse, 
                    Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue);
    
                //Start playing presentation.
                pPre.SlideShowSettings.Run();
                pPre.SlideShowWindow.View.Next();
                //Add a the SingleSlide.pptx into SlidesCollection.pptx
                pPre.Slides.InsertFromFile(presToAdd, 2);
                Thread.Sleep(1000);
                pPre.SlideShowWindow.View.Next();
                Thread.Sleep(1000);
                pPre.SlideShowWindow.View.Next();
                
                //On the screen, you'll see the sequence One Two Three Four.
                
                //pPre.Slides[3].Delete(); //I've tried delete, it also works.
            }
        }
    }
    

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, November 14, 2012 7:22 AM

All replies

  • Hi CaptnCliff,

    Thank you for posting in the MSDN Forum.

    According to your descritpion, I've written the code below. It's an Console Application.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using PowerPoint = Microsoft.Office.Interop.PowerPoint;
    using Office = Microsoft.Office.Core;
    using System.Threading;
    
    namespace ConsoleApplication_ModPresWhilePlaying
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Suppose you have a ppt file named SlidesCollection.pptx in D:\
                //I've create one with 3 slides, 1 slide with title One.
                //2nd slide with title Two. 3rd slide with title Four.
                string presExisting = @"D:\SlidesCollection.pptx";
                //Meanwhile you have a SingleSlide.pptx and you want to add into SlidesCollection.pptx
                //This single slide with title Three.
                string presToAdd = @"D:\SingleSlide.pptx";
    
                PowerPoint._Application pApp = new PowerPoint.Application();
                PowerPoint.Presentation pPre = pApp.Presentations.Open(
                    presExisting, Office.MsoTriState.msoFalse, 
                    Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue);
    
                //Start playing presentation.
                pPre.SlideShowSettings.Run();
                pPre.SlideShowWindow.View.Next();
                //Add a the SingleSlide.pptx into SlidesCollection.pptx
                pPre.Slides.InsertFromFile(presToAdd, 2);
                Thread.Sleep(1000);
                pPre.SlideShowWindow.View.Next();
                Thread.Sleep(1000);
                pPre.SlideShowWindow.View.Next();
                
                //On the screen, you'll see the sequence One Two Three Four.
                
                //pPre.Slides[3].Delete(); //I've tried delete, it also works.
            }
        }
    }
    

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, November 14, 2012 7:22 AM
  • Thank you. Makes a good base from which to start.
    • Edited by CaptnCliff Tuesday, December 11, 2012 9:50 PM
    Tuesday, December 11, 2012 9:49 PM