简体   繁体   中英

Exception trying to load powerpoint presentation

I have a program that I need c# to load a powerpoint presentation. when I do the following it throws an exception

[System.Runtime.InteropServices.COMException] = {"Presentation (unknown member) : Object does not exist."}

It happens on pres.SlideShowWindow.View.First() . I also tried pres.SlideShowWindow.Activate() before this but then got the exception on activate. At the Run line the powerpoint flashes on the screen for just a second and I can make out the slide before it leaves. What am I doing wrong?

try
{
   app = new Microsoft.Office.Interop.PowerPoint.Application();
   app.SlideShowNextSlide += new Microsoft.Office.Interop.PowerPoint.EApplication_SlideShowNextSlideEventHandler(app_SlideShowNextSlide);
   pres = app.Presentations.Open(filename,
        Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue,Microsoft.Office.Core.MsoTriState.msoFalse);
   pres.SlideShowSettings.Run();
   pres.SlideShowWindow.View.First();
 }
 catch (Exception f)
 {
   MessageBox.Show(f.Message);
 }

It turns out

app.SlideShowNextSlide += new Microsoft.Office.Interop.PowerPoint.EApplication_SlideShowNextSlideEventHandler(app_SlideShowNextSlide);

was being fired even on pres.SlideShowWindow.View.First(); which was unexpected. I was hoping it only fired on pres.SlideShowWindow.View.Next(); but that was not the case. Because of logic in app_SlideShowNextSlide() the slideshow was closed before it got to the first slide thus causing the Exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM