我创建了一些 Office 加载项,用于跟踪文档/演示文稿是否已关闭,然后在关闭文档/演示文稿之前执行一些自定义代码。
所有这些代码在 Word 加载项中都没有任何问题,但在 PowerPoint 加载项中我得到一个
“System.Runtime.InteropServices.COMException (0x80048240): Presentation (unknown member): Invalid request. This operation cannot be executed in this event handler.”-关闭 PowerPoint 应用程序时出错。被调用的方法是presentation.Close()。
如果作为 Ribbon 事件处理程序的一部分调用该方法,则该方法可以正常工作,但如果它由任何 Application-evens (或) 调用PresentationClose
,则它无法执行.PresentationBeforeClose
PresentationCloseFinal
presentation.Close()
如前所述,我在没有此问题的 Word 加载项中有相同的代码。我知道这两种产品中的事件处理是不同的,但我仍然无法弄清楚为什么在 PowerPoint 中关闭应用程序或关闭演示文稿时会出现问题。
希望有人能提供一些好的意见。