0

is it possible to trigger event s.t. that a document is saved before Macro ∀ VBA Module run ?

1 Answers1

0

If your question is "how to trigger an event before a presentation is saved" then the answer is as follows. This is a multi-step process.

  1. Add a Class module (not a Standard module) called CEvents and add the following code to it:
Dim WithEvents ppApp As PowerPoint.Application

Sub Initialise()
    Set ppApp = PowerPoint.Application
End Sub

Private Sub ppApp_PresentationBeforeSave(ByVal Pres As Presentation, Cancel As Boolean)
    MsgBox "Before save for " & Pres.Name
End Sub
  1. Follow the process as described in this SO answer: https://stackoverflow.com/a/38295674/11318818

  2. In the same Standard module that you put the MyOnloadProcedure() procedure, add a module-level declaration: Dim mEvents As CEvents

  3. In the MyOnloadProcedure() procedure, replace MsgBox "Hello" with:

Set mEvents = New CEvents
mEvents.Initialise
  1. Save your presentation (it must be macro-enabled eg .pptm). Close and re-open your presentation. Click save to test and you will see the message box.

Note that as soon as you make any module-level edits to your VBA code, the PresentationBeforeSave event will stop triggering until you close and re-open the Presentation ... this is because the module-level variables loose state when you make such edits, state is then re-set when the presentation is re-opened.

JohnM
  • 2,422
  • 2
  • 8
  • 20