PDA

View Full Version : Close PowerPoint with slide show end



Aschrum
08-27-2013, 12:58 AM
Hi,

I would like to close PowerPoint, not only the presentation, after the slide show ends. I guess that should be possible with the event SlideShowEnd, right?
For some reason the event doesn't seem to happen or affect any action.
What's wrong?


As a class:
Public WithEvents App As Application

As a module:
Sub application_SlideShowEnd(ByVal Pres As Presentation)
Dim App As Application
Set App = CreateObject("PowerPoint.Application")
With App.Presentations("makro5.pptm")
.Saved = False
.Quit 'or .Close?
End With
End Sub


Btw: It's impossible to call the macro application_SlideShowEnd. Is it cause it's an event which doesn't have to be called?

André

John Wilson
08-27-2013, 05:30 AM
You cannot fire an event like that.
Private Sub App_SlideShowEnd(ByVal Pres As Presentation)

End Sub

Needs to be in the class module and you also need to instantiate a new instance

In a normal module
Public instAPP As New Class1 'whatever the class is named

Sub Instantiate()
Set instAPP.App = Application
End Sub

Note this cannot be auto run except in an AddIn unless you use the onLoad event in the ribbon
http://www.pptalchemy.co.uk/PowerPoint_Auto_Open_Code.html

IF you are running other macros a much easier (though a little less reliable way) is to use this in a normal module

Sub OnSlideShowTerminate(SW as SlideShowWindow)
SW.Parent.saved=True
App.Quit ' You shouldn't recreate the App I presume you have already done so
End Sub

This will only run reliably if other macros are accessed during the show,

Aschrum
08-28-2013, 06:42 AM
So far I'm running a macro by onload.

Did I get it right that for this reason I won't need the class module?

Do you mean IF I've "dim-ed" App in the class module? Either way (with App-dimming class module or without) it doesn't quit PowerPoint so far. :think:


You shouldn't recreate the App I presume you have already done so

This will only run reliably if other macros are accessed during the show

I run the macros of my two first threads before the show starts, but none while the show is running. Is this the issue? Or do I have to dim App in another macro? Or in the OnSlideShowTerminate macro?

I suppose I'm quite off the track atm...

John Wilson
08-28-2013, 07:15 AM
If you run ANY macro it should work OK.

If you are doing all of this in PowerPoint there's no need to Dim App at all. By default the Application is taken to be the open application.

Application.Quit

If you really want to be sure

PowerPoint.Application.Quit

Aschrum
08-28-2013, 10:15 PM
Works. Nice! Thank you :)

Is there any way to open the marco editor (or the normal view) without disabling macros?

Aschrum
08-29-2013, 04:58 AM
I've changed the last line to ActivePresentation.Close. This way the users will be able to disable macros if they want to.

What's good SW.Parent.Saved = True for? I tought it might be pretending the document has been saved to prevent the Save as dialog. But there is no change without that line. Does it actually save the file? The opposite would be nice. But if this line saves the file, I'd just have to leave out this line, cause as said, it doesn't seem to take any effect.

John Wilson
08-29-2013, 05:35 AM
SW.Parent.Saved = True

Just makes sure the Save dialogue doesan't pop up. Some macros convince ppt that changes have been made and therefore it needs to save before close.

Aschrum
08-29-2013, 06:19 AM
Yeh, just recognized it after turning off the close-line :)