is it possible to trigger event s.t. that a document is saved before Macro ∀ VBA Module run ?
Asked
Active
Viewed 92 times
0
-
Why not call the save-command directly from the macro? – FunThomas Oct 14 '22 at 08:20
1 Answers
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.
- 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
Follow the process as described in this SO answer: https://stackoverflow.com/a/38295674/11318818
In the same Standard module that you put the
MyOnloadProcedure()
procedure, add a module-level declaration:Dim mEvents As CEvents
In the
MyOnloadProcedure()
procedure, replaceMsgBox "Hello"
with:
Set mEvents = New CEvents
mEvents.Initialise
- 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