-
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
-
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
Code:
Public WithEvents PPTEV As Application
Private Sub PPTEV_PresentationBeforeSave(ByVal Pres As Presentation, Cancel As Boolean)
'code
End Sub
Standard module
Code:
Public objEV As New Class1
Sub Auto_Open()
Set objEV.PPTEV = Application
End Sub
-
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!
-
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.