A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Powerpoint, Publisher and Visio » Powerpoint
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

close application from event handler



 
 
Thread Tools Display Modes
  #11  
Old July 16th, 2008, 07:26 PM posted to microsoft.public.powerpoint
Steve Rindsberg
external usenet poster
 
Posts: 9,366
Default close application from event handler

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

  #12  
Old July 16th, 2008, 09:25 PM posted to microsoft.public.powerpoint
theintern
external usenet poster
 
Posts: 58
Default close application from event handler

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


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:47 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.