PowerPoint - VBA - The missing startup glue

Answered PowerPoint - VBA - The missing startup glue

  • 2012年4月4日 4:32
     
     

    Hi

    I see example code like http://msdn.microsoft.com/en-us/library/aa211571(v=office.11).aspx for capturing events without reference to the glue that makes it work.

    I have found some posts with snippets like

    Sub main()
    ' create the appEvents class
    Set myApp = New Class1

    End Sub

    => Can some put me out of my misery and tell me or give me a URL, which tells you how you make this code fire automatically when you run your presentation (which will have the code at the document level (not within the slide)) ?

    Something that links the events to what is missing from the Microsoft help ?

    Thanks

全部回复

  • 2012年4月5日 2:58
    版主
     
      包含代码

    Hi Greg,

    Thanks for posting in the MSDN Froum.

    I'm not sure about the me of "make this code fire automatically". It based on my experience that you can make a macro to show slides. And use a class to subscribe the SlideShowNextSlide event. And there no idea about subscribe the event when PowerPoint lanuching. My mean is this event will be subscribe when a macro has been run. And it will fire when the slide will be shown.

    This is the step to address what I said:

    1. Press Alt+F11 into VBA editor.
    2. Create a Class with following snippet:
    Private WithEvents App As Application
    
    Private Sub App_SlideShowNextSlide(ByVal Wn As SlideShowWindow)
        MsgBox "Show"
    End Sub
    
    Private Sub Class_Initialize()
        Set App = Application
    End Sub
    
    Public Sub ShowSlide()
        App.ActivePresentation.SlideShowSettings.Run
    End Sub

    3.Create a Module with following snippet:

    Dim obj As MyClass
    
    Sub test()
        
        Set obj = New MyClass
        
        obj.ShowSlide
        
    End Sub

    4.Run the macro.

    This is a screen shooting:

    I hope it can help you.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

  • 2012年4月5日 5:03
     
     

    Thanks Tom

    It works, however this works because i ran the macro.

    => How do i get the macro to be run automatically when you start running the slideshow ?
    i.e. not manually running a macro

    => On more searching it seems i need to create a PowerPoint Add-In (i am using 2010) ? Pity they did not have a simple setting to run a macro at start..
    Found http://msdn.microsoft.com/en-us/library/gg597509.aspx

    Hopefully there is a plug that runs "Main" sub to allow your VBA to run (if both a plug-in and vba code can co-exist)

    Once again thanks

    Note: As per my other post, the extra code for App_SlideShowNextBuild does not fire

    Private Sub App_SlideShowNextBuild(ByVal Wn As SlideShowWindow)

    Debug.Print "SlideShowNextBuild Slide=" & Wn.View.CurrentShowPosition

    MsgBox ("In SlideShowNextBuild")

    End Sub

    p.s. you should make this post a KB !!



  • 2012年4月6日 6:23
    版主
     
     

    Hi Greg,

    As far as I know PowerPoint can't execute macro automatically. Develop an add-in to handle this issue is a work round. However if you develop an add-in, you are able to scribute SlideShowNextSlide event directly. I think VBA marco will meaningless in Add-in.

    <<p.s. you should make this post a KB!!>>

    OK, I will suggest it in internal channel. However I have no permission to publish KB, I just feedback your wish to Microsoft. Thanks for your understanding.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

  • 2012年4月6日 19:41
     
     已答复

    Greg,

    You need to create an add-in to which has two macros which fire when they load (Auto_Open) and unload (Auto_Close). You can initialize your event handler in the auto_open.

    This free add-in - http://skp.mvps.org/autoevents.htm - does exactly that and it invokes the same within any presentation that has these macros in them

    • Sub Auto_Open() -
      Gets executed immediately after the presentation is opened.

    • Sub Auto_Close() -
      Sub Auto_Print() -
      Sub Auto_ShowBegin()
      - Gets executed when the show begins.

    • Sub Auto_ShowEnd() -
      Gets executed when the show ends.

    • Sub Auto_NextSlide(Index as
      Long)
      - Gets executed before the slideshow moves onto the next slide. Index represents the SlideIndex of the Slide
      about to be displayed

    If you search hard enough on the web you will also find a few unsupported macros which fire in PowerPoint without the need of an add-in when a slide show is started.


    Regards, Shyam