14
votes

I'd like to be able to advance through a Powerpoint presentation by pressing buttons in a Windows form. Here's some code I've found from http://bytes.com/topic/c-sharp/answers/272940-open-powerpoint-presentation-c-window-form that opens a Powerpoint presentation slide show:

Microsoft.Office.Interop.PowerPoint.Application oPPT;
Microsoft.Office.Interop.PowerPoint.Presentations objPresSet;
Microsoft.Office.Interop.PowerPoint.Presentation objPres;

//the location of your powerpoint presentation
string strPres = @"filepath";

//Create an instance of PowerPoint.
oPPT = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();

// Show PowerPoint to the user.
oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;

objPresSet = oPPT.Presentations;

//open the presentation
objPres = objPresSet.Open(strPres, MsoTriState.msoFalse,
MsoTriState.msoTrue, MsoTriState.msoTrue);

objPres.SlideShowSettings.Run();

I haven't found any methods that can advance through the slides, however. Any ideas?

(Really what I'm trying to do is use the WiiRemote to advance the slides, for a student project).

4

4 Answers

10
votes

The method to advance programatically is "SlideShowWindow.View.Next". You can also use "SlideShowWindow.View.Previous" to go backwards.

3
votes

Looks like there is a method called GotoSlide that will work, just needed to dig a little more! For instance:

int i = 0;
while (true)
{
    i++;
    objPres.SlideShowWindow.View.GotoSlide(i, MsoTriState.msoFalse);
    System.Threading.Thread.Sleep(5000);
}
1
votes

I think you could do this to run them one at a time, for instance:

oSettings = objPres.SlideShowSettings
oSettings.StartingSlide = 3
oSettings.EndingSlide = 3

oSettings.Run()
Do While oApp.SlideShowWindows.Count >= 1
    System.Windows.Forms.Application.DoEvents()
Loop
0
votes

You might have get a answer for you question, However for the people who will face the same kind of problem I will send a link for a opensource C# code which handles this kind of situation smoothly.

https://code.msdn.microsoft.com/office/How-to-Automate-control-23cd2a8f

Download the zip file, inside there is a c# project which controls power point slides perfectly

Best wishes folks.