Powerpoint VBA App_SlideShowBegin
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10357634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Powerpoint VBA App_SlideShowBegin
提问by Kyle Uithoven
In order to use the SlideShowBegin event in Powerpoint, you have to have a Class Module configured the following way:
为了在 Powerpoint 中使用 SlideShowBegin 事件,您必须按以下方式配置类模块:
Public WithEvents App As Application
Private Sub App_SlideShowBegin(ByVal Wn As SlideShowWindow)
MsgBox "SlideShowBegin"
End Sub
Then, inside of a non-class module, you have to create an object of that type and set the App to Application.
然后,在非类模块中,您必须创建该类型的对象并将 App 设置为 Application。
Dim X As New Class1
Sub InitializeApp()
Set X.App = Application
End Sub
Now, the only issue I have is, if you don't manually called InitializeApp with the Macro Menu in Powerpoint, the events don't work. You have to call this sub before anything can called at the beginning of a slideshow INCLUDING this sub.
现在,我唯一的问题是,如果您不使用 Powerpoint 中的宏菜单手动调用 InitializeApp,则事件将不起作用。您必须先调用此子程序,然后才能在幻灯片开始时调用任何内容,包括此子程序。
How can I go about calling this sub before running my powerpoint? Is there a better way to do this?
在运行我的 powerpoint 之前,我该如何调用这个子程序?有一个更好的方法吗?
EDIT:
编辑:
I've tried using Class_Initialize but it only gets called once it is first used or you make a statement like Dim X as Class1; X = new Class1
我试过使用 Class_Initialize 但它只有在第一次使用时才会被调用,或者你做了一个类似的声明 Dim X as Class1; X = new Class1
采纳答案by Steve Rindsberg
Usually event handlers are installed as part of an add-in, where you'd initialize the class in the Auto_Open subroutine, which always runs when the add-in loads. If you want to include an event handler in a single presentation, one way to cause it to init is to include a shape that, when moused over or clicked fires a macro, which inits your event handler and goes to the next slide.
通常,事件处理程序作为加载项的一部分安装,您可以在其中初始化 Auto_Open 子例程中的类,该子例程始终在加载项加载时运行。如果您想在单个演示文稿中包含一个事件处理程序,使其初始化的一种方法是包含一个形状,当鼠标悬停或单击时会触发一个宏,该宏初始化您的事件处理程序并转到下一张幻灯片。