PowerPoint演示文稿,演示完毕后关闭事件

3

PowerPoint 2007仅公开一个演示文稿关闭事件(PresentationClose),该事件在演示文稿关闭之前触发。

在我正在处理的几个代码片段中,我需要跟踪打开的演示文稿,因此需要对其中一个进行反应。

通常,PowerPoint提供的事件已经足够了。但是在以下情况下不够用。

如果演示文稿在关闭时尚未保存,PowerPoint会显示一个对话框,询问用户是否要保存演示文稿。如果用户单击是或否,则一切正常,因为演示文稿最终将被关闭。但是,他还可以选择取消关闭...

在这种情况下,关闭事件将被触发,演示文稿仍然存在,但我的应用程序不知道它。

有人能给我提供某种解决方法吗?也许是在用户单击取消后引发的事件?

2个回答

1

你可能需要 PresentationBeforeClosePresentationCloseFinal,这是在 PowerPoint 2010 中添加的。

如果用户在提示时点击“是”保存并在“保存演示文稿”窗口中点击“取消”退出,则可能出现同样的问题。这仍然使演示文稿在应用程序中保持活动状态。

我想出的 PowerPoint 2007 解决方法(灵感来自此处):


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
    }
}

谢谢忍者,干得好!(虽然我在2010年知道了这个事件,但我在2007年还没有足够的智慧 :-)) - Julien V.
@JulienV. - 很高兴能帮到你!如果它有效,请接受为答案。这将有助于其他发现此问题的人。 - SliverNinja - MSFT
1
实际上,本地化仍然是一个问题,因为“是”和“否”的快捷键会随着用户界面语言的变化而改变。 - Julien V.
1
还有一个问题是用户触发了“另存为”对话框并取消操作... - Julien V.

0

我认为类似这样的代码可以实现这个功能:

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
      Else

      End If
    Next
  End if

1
它不会,因为当事件被触发时,演示文稿总是打开的(在关闭事件之前...) - Julien V.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接