PowerPoint 2007 only exposes a single presentation close event (PresentationClose), which is raised before the closing of the presentation.
In several pieces of code I'm working on, I need to keep track of opened presentations, and therefore to react to one of them being closed.
Generally the event proposed by PowerPoint is enough. Except in the following case.
If the presentation has not been saved when it is closed, PowerPoint displays a dialog asking the user if he wants to save his presentation or not. If the user clicks yes or no, everything is fine since the presentation will eventually be closed. But he can also select to cancel closure...
In this case, the close event is raised, the presentation is still there but my application does not know it.
Can someone give me some kind of workaround? Maybe a event raised after the user clicks on cancel?
You probably want PresentationBeforeClose or PresentationCloseFinal which was added in PowerPoint 2010.
You could also have this same problem occur if the user clicks 'Yes' to save at the prompt and then clicks 'Cancel' to exit the Save Presentation window. This still keeps the presentation alive within the application.
void Application_PresentationClose(PowerPoint.Presentation presentation)
{
if (presentation.Saved == MsoTriState.msoFalse)
{
MessageBoxResult savePrompt = MessageBox.Show(string.Format("Do you want to save the changes you made to {0}?", presentation.Application.ActiveWindow.Caption), Globals.ThisAddIn.Application.Name, MessageBoxButton.YesNoCancel, MessageBoxImage.Warning, MessageBoxResult.Yes);
if (savePrompt == MessageBoxResult.Yes)
System.Windows.Forms.SendKeys.Send("Y"); // trigger default SaveAs prompt
else if (savePrompt == MessageBoxResult.No)
System.Windows.Forms.SendKeys.Send("N"); // discard presentation
else
System.Windows.Forms.SendKeys.Send("{ESC}"); // disables default SaveAs prompt
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With