Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Nov 2002
    London, Gtr London, England
    Thanked 0 Times in 0 Posts

    Automatic macros (2K)

    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?


  2. #2
    3 Star Lounger
    Join Date
    Jul 2002
    Memphis, Tennessee, USA
    Thanked 0 Times in 0 Posts

    Re: Automatic macros (2K)

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


  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 94 Times in 90 Posts

    Re: Automatic macros (2K)

    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. <LI>Fire up the VB Editor and create a new class module (which I rename to clsPPTevents). In this module I add the line:
      <pre>Public WithEvents ppApp As PowerPoint.Application</pre>

      <LI>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:
      <pre>Private Sub ppApp_PresentationClose(ByVal Pres As Presentation)

      End Sub</pre>

      This is where I will put some code later. For quick reference, it ends up like this:
      <pre>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</pre>

      <LI>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:
      <pre>Dim PPevts As New clsPPTevents</pre>

      <LI>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:
      <pre>Sub DoSetup()
      ' Snag application events
      Set PPevts.ppApp = PowerPoint.Application
      End Sub</pre>

      <LI>Last but not least, my code to "mirror" the presentation is roughly as follows (I have simplified the local path):
      <pre>Sub MirrorPres(ppFile As Presentation)
      FileCopy ppFile.FullName, Replace(ppFile.FullName, "L:", "C:PPT", , , vbTextCompare)
      End Sub</pre>
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts