Consulting

Results 1 to 4 of 4

Thread: Run Macro BeforeSave

  1. #1
    VBAX Newbie
    Joined
    Sep 2018
    Posts
    2
    Location

    Run Macro BeforeSave

    Hello All,
    I'm almost embarrassed to be asking this because I can make things like this work in Excel but for some reason PowerPoint is stumping me.

    I've got a macro that generates a table of contents and I'd like to run it whenever someone saves the powerpoint file. I'd also like a message box asking if they want to update the TOC or not.

    Below is the code I have so far (saved in a module, but have also tried in a class module. But the difference between these two is starting to go beyond my level of understanding). When I hit save...nothing happens. No message box, no updated TOC, nothing. The file just saves. I'm clearly doing something wrong with the module/class settings here but I just don't know what...

    Any help would be appreciated

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim Msg As String, Ans As Variant


    Msg = "Update Table of Contents?"


    Ans = MsgBox(Msg, vbYesNo)


    Select Case Ans


    Case vbYes

    Call SQ_TOC_Writer

    Case vbNo
    GoTo Quit:
    End Select


    Quit:

    End Sub

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Don't be embarressed PowerPoint can't do this out of the box.

    You can write this into a class module but it only works properly in a ppam AddIn as Auto_open does NOT run when you open a presentation only when you load an AddIn

    Class Module code

    Public WithEvents PPTEV As Application
    
    
    Private Sub PPTEV_PresentationBeforeSave(ByVal Pres As Presentation, Cancel As Boolean)
    'code
    End Sub
    
    Standard module
    
    
    
    Public objEV As New Class1
    
    
    Sub Auto_Open()
    Set objEV.PPTEV = Application
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Newbie
    Joined
    Sep 2018
    Posts
    2
    Location
    Thanks for the quick feedback John Wilson,
    Your code works beautifully! I may have some challenges with using the ppam format but you've helped me create exactly what I was looking for, thank you!

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    You might be able to use the ribbon load event to fire the auto open macro

    See this page on our site

    Bear in mind it will not work in a ppsm file (no ribbon) or from a macro enabled template.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

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