I'm writing an application that uses the PowerPoint interop library for Office 2010. It's supposed to open PowerPoint, load a presentation, and wait for the user to save the presentation after making changes. I want the application to upload the presentation to a server once updated.
The problem I'm having is that the PresentationSave
or PresentationBeforeSave
events are not being triggered when the presentation is saved.
Here's the code I've used:
private void startPPT()
{
app = new ApplicationClass();
app.WindowState = PpWindowState.ppWindowMaximized;
app.Visible = MsoTriState.msoTrue;
app.PresentationBeforeSave += new EApplication_PresentationBeforeSaveEventHandler(app_PresentationBeforeSave);
app.PresentationSave += new EApplication_PresentationSaveEventHandler(app_PresentationSave);
Presentation ppt;
//check if it's pptx or ppt and open accordingly
FileInfo fi = new FileInfo(filename);
if (fi.Extension == ".pptx")
{
//version 2007
ppt = app.Presentations.Open2007(filename, MsoTriState.msoFalse, MsoTriState.msoFalse);
}
else
{
//version 2003 or older
ppt = app.Presentations.Open(filename, MsoTriState.msoFalse, MsoTriState.msoFalse);
}
}
void app_PresentationSave(Presentation Pres)
{
MessageBox.Show("Saved");
}
Any ideas why it isn't working?