取消PowerPoint事件的参数Application.PresentationBeforeSave不工作 [英] cancel parameter of PowerPoint event Application.PresentationBeforeSave not working

查看:153
本文介绍了取消PowerPoint事件的参数Application.PresentationBeforeSave不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试响应PowerPoint事件Application.PresentationBeforeSave()并通过将事件参数Cancel设置为True来取消保存。这似乎不起作用。我正在使用PowerPoint 2013,我没有尝试过不同的版本。

I am trying to respond to the PowerPoint event Application.PresentationBeforeSave() and cancel the save by setting the event parameter Cancel to True. This does not seem to work. I am using PowerPoint 2013, I have not tried it with different versions.

这是我的VBA代码。这将创建一个新的PowerPoint应用程序,添加一个新的演示文稿并注册该事件。保存演示文稿时,MessageBox"保存已取消"出现但保存未被取消:

Here is my VBA code. This creates a new PowerPoint application, adds a new presentation and registers the event. When saving the presentation the MessageBox "save canceled" appears but the save is NOT canceled:

Class PPClass:

Class PPClass:

Option Explicit
Public WithEvents PPTEvent As PowerPoint.Application

Private Sub PPTEvent_PresentationBeforeSave(ByVal Pres As PowerPoint.Presentation, Cancel As Boolean)
    Cancel = True
    MsgBox "Save canceled."
End Sub




模块模块1:

Dim cPPTObject As PPClass
Sub PPTest()
    Set cPPTObject = New PPClass
    Set cPPTObject.PPTEvent = CreateObject("PowerPoint.Application")
    Dim prsntPP As PowerPoint.Presentation
    Dim slidePP As PowerPoint.Slide
    
    'make the PowerPoint window visible:
    cPPTObject.PPTEvent.Visible = True
    'maximize PowerPoint window:
    cPPTObject.PPTEvent.WindowState = ppWindowMaximized
    
    'create a new presentation in PowerPoint:
    Set prsntPP = cPPTObject.PPTEvent.Presentations.Add
    
    'ADD FIRST SLIDE:
    'The title slide (ppLayoutTitleOnly) has 1 shape, Shape(1) is the title, you can add your own shapes to the slide:
    'add a title slide to the new presentation:
    Set slidePP = prsntPP.Slides.Add(Index:=1, Layout:=ppLayoutTitleOnly)
End Sub

我做错了吗?它适用于Word。

Is there something I am doing wrong? It works fine with Word.

感谢您的帮助。

此致,

Max Trauth

Max Trauth

推荐答案

Hello Max,

Hello Max,

我刚检查了
PresentationBeforeSave
事件。它就像一个魅力,取消参数设置为true,并且演示文稿没有像我预期的那样保存。尝试为cancel参数指定ByRef修饰符:

I have just checked the PresentationBeforeSave event of the Application class. It works like a charm, the Cancel parameter was set to true and the presentation was not saved as I expected. Try to specify the ByRef modifier for the cancel parameter:

Private Sub PPTEvent_PresentationBeforeSave(ByVal Pres As PowerPoint.Presentation, ByRef Cancel As Boolean)
    Cancel = True
    MsgBox "Save canceled."
End Sub




让我知道它是否有帮助。


Let me know whether it helps.


这篇关于取消PowerPoint事件的参数Application.PresentationBeforeSave不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆