PowerPoint, después del evento de cierre de la presentación

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?

preguntado el 01 de febrero de 12 a las 14:02

2 Respuestas

Probablemente quieras PresentationBeforeClose or PresentationCloseFinal que fue agregado en 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.

PowerPoint 2007 workaround I came up with (inspiration from here):

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
            System.Windows.Forms.SendKeys.Send("{ESC}"); // disables default SaveAs prompt

Respondido el 20 de junio de 20 a las 12:06

Thanks Ninja, nicely done! (Knew about the event in 2010 but lacked the brains for 2007 :-)) - Julien V.

@JulienV. - Glad it helped you! Please accept as answer if it works. This will help others who find this. - SliverNinja - MSFT

Actually there is still the issue of localization, as the shortcut to yes and no change with UI language. - Julien V.

And There is also the issue of a user triggering the saveas dialog and canceling... - Julien V.

Something like this would do it, I think:

Private Sub PPTEvent_PresentationClose(ByVal Pres As Presentation)

  Dim x as Long
  with Application.Presentations
  If .Count > 0 Then
    For x = 1 to .Count
      If .Item(x) = Pres Then
         ' the presentation that triggered the event
         ' is still open; user must've canceled

      End If
  End if

Respondido 02 Feb 12, 19:02

It won't since when the event is triggered, the presentation is always opened (before close event...) - Julien V.

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.