Powerpoint Event handling - Prevent New Presentation
I am creating a Powerpoint Add-in. I would like to restrict user from either:
- Create New Presentation
- Open an existing Presentation
I have used this tutorial/overview to trap the NewPresentation and PresentationOpen events. I would like to close any presentation initialized through these events before the user can interact with it. When I try to close it using .Close method, I receive an error (screenshot below).
In my class module, I have the following to trap the NewPresentation event. This works fine, I receive the message box and Pres is a valid Presentation object that can be passed to the CloseNewPres routine.
Private Sub PPTEvent_NewPresentation(ByVal Pres As Presentation) MsgBox "You cannot use this Charting tool with multiple presentations.", vbInformation CloseNewPres Pres End Sub
In a standard module, I have the CloseNewPres routine, which I expect to close the "New" presentation:
Sub CloseNewPres(Pres As Presentation) Application.Presentations(Pres.Name).Close 'Pres.Close '<~~ This also fails.' End Sub
I receive the following error.
Any thoughts on why this is happening? Or what I can do to close these presentations?
In my opinion you need to use another event which is quite similar to one you used:
Private Sub PPApp_AfterNewPresentation(ByVal Pres As Presentation)
If I set Pres.Close within proposed one it really closes new created presentation.