PowerPoint 2007仅公开一个演示文稿关闭事件(PresentationClose),该事件在演示文稿关闭之前引发。
在我正在处理的几段代码中,我需要跟踪打开的演示文稿,因此需要对其中一个关闭的演示文稿做出反应。
一般来说,PowerPoint提出的活动就足够了。以下情况除外。
如果演示文稿在关闭时尚未保存,PowerPoint将显示一个对话框,询问用户是否要保存其演示文稿。如果用户单击“是”或“否”,则一切正常,因为演示文稿最终将关闭。但他也可以选择取消关闭...
在这种情况下,close事件被引发,演示文稿仍然在那里,但我的应用程序不知道它。
有人能给我一些变通方法吗?也许是用户单击cancel后引发的事件?
发布于 2012-02-02 23:57:59
您可能需要在PowerPoint 2010中添加的PresentationBeforeClose或PresentationCloseFinal。
如果用户在出现提示时单击“Yes”保存,然后单击“Cancel”退出“save Presentation”窗口,也可能会出现同样的问题。这仍然会使表示在应用程序中保持活动状态。
我想出的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
}
}发布于 2012-02-02 23:51:09
我认为,像这样的东西就可以做到:
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 ifhttps://stackoverflow.com/questions/9097230
复制相似问题