有像excel那样的presentationclose选项吗?

问题描述 投票:0回答:1
哈韦洛,

我在 ThisWorkbook 模块中有一个 excel 例程,它检测“保存”或“关闭”事件,并在执行“保存”或“关闭”之前执行一些命令。

Powerpoint中有类似的东西吗?

谢谢你

vba powerpoint
1个回答
0
投票
    您需要一个能够触发 PowerPoint 事件的类。因此,请在项目中插入一个类模块,将其命名为“clsPPEvents”并将以下代码粘贴到其中:
Option Explicit Public WithEvents App As Application Private Sub App_PresentationClose(ByVal Pres As Presentation) MsgBox "Presentation """ & Pres.Name & """ is closing..." 'do here whatever you need to do before presentation closing... End Sub

    请复制标准模块中的下一个代码。它将初始化上述类以触发 PowerPoint 应用程序的事件:
Option Explicit Public myApp As New clsPPEvents Sub EnableEvents() Set myApp.App = Application End Sub

  1. EnableEvents
     演示文稿打开时必须调用 Sub。由于此时 PowerPoint 事件尚未启用,因此您需要找到一种方法来调用它以初始化该类。它可以通过加载项来完成,这有点复杂,或者使用功能区事件 (
    OnLoad
    )(在所需的演示文稿打开时触发)。我将向您展示第二种方法。
3.1 将下一个代码复制到标准模块中(与之前使用的相同,或另一个):

Public Sub onLoadRibbon(myRibbon As IRibbonUI) Debug.Print "Ribbon Loaded" 'just to see that it has been called EnableEvents 'initialize the events class End Sub
保存演示文稿并关闭它。

3.2 上述代码必须在加载时由Ribbon调用。因此,您需要下载“Office RibbonX 编辑器”(从

此处。下载 zip 存档,将其内容解压到特定文件夹中并运行 CustomUIEditor.exe

。要了解如何使用它,请观看 
next 视频。它展示了如何在 Excel 功能区中使用,但必须以与 PowerPoint 完全相同的方式使用。 上面的代码必须在加载期间由 Ribbon 调用。因此,您需要下载“Office RibbonX 编辑器”(从此处。下载 zip 存档,将其内容解压到特定文件夹中并运行 CustomUIEditor.exe
。要了解如何使用它,请观看 
next 视频。它展示了如何在 Excel 功能区中使用,但必须以与 PowerPoint 完全相同的方式使用。

使用它并复制插入的下一个 XML 代码

customUI14.xml

(适用于 Office 2010 或更新版本):

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="onLoadRibbon" ></customUI>
或 Office 2007 的 

customUI.xml

 中的下一个:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="onLoadRibbon" ></customUI>
同时插入 

custom UI

 演示文稿将在 2007 年以上的所有 Office 版本(含)中正常工作。

Validate

检查XML代码是否正确,如果正确,请按
Save
按钮。

    现在,打开演示文稿,对其进行任何您需要的操作,然后尝试关闭它。
  1. App_PresentationClose
     事件将被触发,您将收到消息 
    "Presentation " & Presentation Name & " is closing..."
    
    
请在测试建议的解决方案后发送一些反馈。

如果有些事情不够清楚,请随时专门要求澄清

© www.soinside.com 2019 - 2024. All rights reserved.