【问题标题】:PowerPoint, after presentation close eventPowerPoint,演示结束事件后
【发布时间】:2012-02-24 05:11:21
【问题描述】:

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

在我正在处理的几段代码中,我需要跟踪打开的演示文稿,因此要对其中一个被关闭做出反应。

一般情况下,PowerPoint 提出的事件就足够了。以下情况除外。

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

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

有人可以给我一些解决方法吗?可能是用户点击取消后引发的事件?

【问题讨论】:

    标签: events vsto powerpoint


    【解决方案1】:

    您可能想要PresentationBeforeClosePresentationCloseFinal,这是在PowerPoint 2010 中添加的。

    如果用户在提示符处单击“是”保存,然后单击“取消”退出“保存演示文稿”窗口,您也可能会遇到同样的问题。这仍然使演示文稿在应用程序中保持活跃。

    我想出的 PowerPoint 2007 解决方法 (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
            else
                System.Windows.Forms.SendKeys.Send("{ESC}"); // disables default SaveAs prompt
        }
    }
    

    【讨论】:

    • 谢谢忍者,干得好! (知道 2010 年的事件,但缺乏 2007 年的大脑 :-))
    • @JulienV。 - 很高兴它帮助了你!如果可行,请接受作为答案。这将帮助找到此内容的其他人。
    • 其实还是有本地化的问题,作为yes和no的捷径,随着UI语言的变化。
    • 还有用户触发saveas对话框并取消的问题...
    【解决方案2】:

    我认为这样可以做到:

    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
    

    【讨论】:

    • 它不会因为触发事件时,总是打开演示文稿(在关闭事件之前...)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-05
    • 2012-01-04
    • 1970-01-01
    • 2016-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多