close application from event handler

T

theintern

I'd like to close PowerPoint from an event handler, but it gives me an error
when i try to do so. Right now i have it set up so that when PP is open a
macro runs the show for a set amount of time. At the end of that, the show
is closed (ActivePresentation.close) and then i'd like PP to close as well
(Application.quit) but apparently this code can't be run off an event. Any
ideas?

thanks
scott
 
T

theintern

fyi, the reason i need the application to close is so that the macro will
auto run again the next time the application is open. i.e. the macro won't
auto run if the presentation is re-opened, but PowerPoint was never closed
(because the add-in wasn't reloaded).
 
T

theintern

thanks for getting back to me.

Right now i have it firing on "AfterPresentationOpen", and the command
'ActivePresentation.close' works fine. However, with this command, the macro
isn't fired each time my presenation is opened (because PowerPoint never
closes i guess?). But if i try and switch it to PresentationOpen, then the
command 'ActivePresentation.close' doesn't work anymore. It tells me I can't
call that from an event handler. Seems like something isn't working the way
it should...thoughts?

thanks
scott
 
T

theintern

Yeah, neither PresentationOpen nor AfterPresentationOpen fire except for the
first time. To fire again, powerpoint has to be completely closed and then
reopened. Is there a way to get them to fire everytime a presenation is
opened (even if PP is already open) and/or close powerpoint completely (it
doesn't like using Application.close from an event handler.)

thanks
scott
 
T

theintern

putting it in the add-in didn't work. no error message, but it didn't close
anything. basically it was like it ignored the code. here is how i had it.

Public WithEvents PPTEvent As Application

Private Sub PPTEvent_PresentationOpen(ByVal Pres As Presentation)
CreateShow
End Sub

Public Sub ByeBye()
Application.Quit
End Sub

As far as the error...if i try and use "application.quit" with
"PresentationOpen" i get:

Run-time error "-2147188160(80048240)":
Application(unknown member): Invalid request. This operation cannot be
performed in this event handler.

thanks for helping me with this.
scott
 
T

theintern

I tried the following as well. Same error message as other strategy.

Public WithEvents PPTEvent As Application

Private Sub PPTEvent_PresentationOpen(ByVal Pres As Presentation)
CreateShow
ByeBye
End Sub

Public Sub ByeBye()
Application.Quit
End Sub
 
T

theintern

no go. same error as before, can't call this from an event handler. so
here's how i have it set up:
i have 2 modules, and 1 class

the first module is called AutoRun:
Public cPPTObject As New EventClass

Sub Auto_Open()
'set an application reference to the event-enabled object
Set cPPTObject.PPTEvent = Application
End Sub

the second module is called CreateShowmod:
sub CreateShow()
a bunch of code...
end sub
sub byebye
application.quit
end sub

the class is called EventClass:
Public WithEvents PPTEvent As Application

Private Sub PPTEvent_PresentationOpen(ByVal Pres As Presentation)
CreateShow
End Sub

it just really doesn't want me to call application.quit from an event
handler. if only afterpresentationopen would fire every time, even if PP
wasn't fully closed...
i'm trying to figure out some other ways around this as well, seeing if it
will let me call application.quit from a different event. this is so
frustrating.

thanks
scott
 
T

theintern

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top