• Automatic macros (2K)

    Author
    Topic
    #390883

    Dear Woodytes,

    Does Powerpoint support macros that, for example, run on creating or opening a file (like Word does) if so what are the names of these?

    liz

    Viewing 1 reply thread
    Author
    Replies
    • #696275

      PowerPoint is different than Word in that respect. Read more here.

      LennyJo

    • #696324

      Individual presentation files can have macros in them, it’s the global piece that’s hard to use.

      If you are familiar with application level events in Word, PowerPoint has equivalents for many of them. Although more complex to use, they can take the place of AutoNew, AutoOpen, etc. Here’s an example: I want to copy a backup of presentations saved on our network server to my C drive. I need to set up an event procedure that recognizes when I’m closing a presentation. Here’s what I do.

      1. Fire up the VB Editor and create a new class module (which I rename to clsPPTevents). In this module I add the line:
        Public WithEvents ppApp As PowerPoint.Application
      2. If you select ppApp in the left drop-down list above the code area, the right list will display a huge number of events you can detect (it also creates stub procedure for one of them, never the one I want, I can delete it later). I pick PresentationClose and the VBE inserts a stub for me:
        Private Sub ppApp_PresentationClose(ByVal Pres As Presentation)
         
        End Sub

        This is where I will put some code later. For quick reference, it ends up like this:

        Private Sub ppApp_PresentationClose(ByVal Pres As Presentation)
        If MsgBox("Mirror presentation to your hard drive?", vbYesNo) _
                = vbYes Then
            MirrorPres Pres
        End If
        End Sub
      3. Insert a new code module (regular, not class). Here you declare a variable that will hook up with your event code in your class module:
        Dim PPevts As New clsPPTevents
      4. Then I write a initialization procedure for PPevts. In a COM add-in, there is a special place you can stick this code so it fires up automatically when the add-in is loaded. I don’t know if you can do that in a PPA add-in. For sure it’s not automatic in a regular PPT file. Anyway, to initialize my event handler(s), I would run this macro:
        Sub DoSetup()
        ' Snag application events
        Set PPevts.ppApp = PowerPoint.Application
        End Sub
      5. Last but not least, my code to “mirror” the presentation is roughly as follows (I have simplified the local path):
        Sub MirrorPres(ppFile As Presentation)
        FileCopy ppFile.FullName, Replace(ppFile.FullName, "L:", "C:PPT", , , vbTextCompare)
        End Sub

      The timing on PowerPoint events is more crude than with Word and Excel, where you get options to do thing Before (such as BeforeSave, BeforeClose and BeforePrint), but it might suit your needs otherwise. Hope this helps.

    Viewing 1 reply thread
    Reply To: Automatic macros (2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: