So i got it working. It was a pain, but it works. First i got it working
using a second handler, SlideShowEnd, to call ActivePresentation.close, but
after that started working i decided to try AfterPresentationOpen again, and
then that started working as well. I don't know. This was so frustrating
but i'm glad it works now.
Lessons Learned:
1) AfterPresentationOpen can call ActivePresentation.close
2) PresentationOpen cannot call ActivePresentation.close
3) Neither can call Application.quit
4) There is almost always another way around it
Thanks so much to you all for your help!
Scott
"Steve Rindsberg" wrote:
In article , Theintern wrote:
no go. same error as before, can't call this from an event handler.
OK, I'm seeing the same thing.
But let's go back to the starting point. You're trying to shut down PPT because the
presentation open event only fires once, right? There's something wrong with that. It
should fire every time you open a presentation, as long as the event trap is still set.
Modifying the code in any way will invalidate the trap, as will execution errors and
compile errors. Closing the presentation with the code in it will also make everything
stop working.
So long as this is all in an addin, not a PPT file, and there are no errors (or you
trap them thoroughly), the events should continue to fire as long as PPT is running.
So with that said, is there still some reason why you need to quit PPT?
(And does anyone have any suggestions for how to do it, 'cause I'm still curious about
that)
Here's a modified example; you can run this from within a PPT as long as you manually
fire the Auto_Open sub first.
'In a regular module:
Option Explicit
Public cPPTObject As New EventClass
Sub Auto_Open()
'set an application reference to the event-enabled object
Set cPPTObject.PPTEvent = Application
End Sub
Sub CreateShow()
' a bunch of code...
MsgBox "CreateShow"
End Sub
Public Sub ByeBye()
MsgBox "ByeBye"
End Sub
' in a class module named EventClass
Option Explicit
Public WithEvents PPTEvent As Application
Private Sub PPTEvent_PresentationClose(ByVal Pres As Presentation)
ByeBye
End Sub
Private Sub PPTEvent_PresentationOpen(ByVal Pres As Presentation)
CreateShow
End Sub
Private Sub PPTEvent_SlideShowBegin(ByVal Wn As SlideShowWindow)
MsgBox "Starting show"
End Sub
Private Sub PPTEvent_SlideShowEnd(ByVal Pres As Presentation)
MsgBox "Ending show"
'ByeBye
End Sub
-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Living in the Help Center at PowerPoint Live
Sept 21-24, San Diego CA, USA
www.pptlive.com