PC Review


Reply
Thread Tools Rate Thread

close application from event handler

 
 
theintern
Guest
Posts: n/a
 
      14th Jul 2008
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
 
Reply With Quote
 
 
 
 
theintern
Guest
Posts: n/a
 
      14th Jul 2008
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).

"theintern" wrote:

> 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

 
Reply With Quote
 
Chirag
Guest
Posts: n/a
 
      14th Jul 2008
Looks like you actually need to write event handler code for
PresentationOpen event. PresentationOpen() application event is fired by
PowerPoint whenever an existing presentation is opened.

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html

"theintern" <(E-Mail Removed)> wrote in message
news:68888CE6-E0CB-48EA-BB0D-(E-Mail Removed)...
> 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).
>
> "theintern" wrote:
>
>> 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


 
Reply With Quote
 
theintern
Guest
Posts: n/a
 
      14th Jul 2008
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

"Chirag" wrote:

> Looks like you actually need to write event handler code for
> PresentationOpen event. PresentationOpen() application event is fired by
> PowerPoint whenever an existing presentation is opened.
>
> - Chirag
>
> PowerShow - View multiple PowerPoint slide shows simultaneously
> http://officeone.mvps.org/powershow/powershow.html
>
> "theintern" <(E-Mail Removed)> wrote in message
> news:68888CE6-E0CB-48EA-BB0D-(E-Mail Removed)...
> > 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).
> >
> > "theintern" wrote:
> >
> >> 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

>

 
Reply With Quote
 
theintern
Guest
Posts: n/a
 
      14th Jul 2008
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

"Chirag" wrote:

> Looks like you actually need to write event handler code for
> PresentationOpen event. PresentationOpen() application event is fired by
> PowerPoint whenever an existing presentation is opened.
>
> - Chirag
>
> PowerShow - View multiple PowerPoint slide shows simultaneously
> http://officeone.mvps.org/powershow/powershow.html
>
> "theintern" <(E-Mail Removed)> wrote in message
> news:68888CE6-E0CB-48EA-BB0D-(E-Mail Removed)...
> > 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).
> >
> > "theintern" wrote:
> >
> >> 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

>

 
Reply With Quote
 
theintern
Guest
Posts: n/a
 
      14th Jul 2008
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

"Steve Rindsberg" wrote:

> In article <F5474780-45D8-4143-AC02-(E-Mail Removed)>, Theintern
> wrote:
> > 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?

>
> What's the exact error message you get.
>
> And have you tried firing a sub in your addin from within the event handler
> class:
>
> ByeBye
>
> Public Sub ByeBye()
> Application.Quit
> End Sub
>
> -----------------------------------------
> Steve Rindsberg, PPT MVP
> PPT FAQ: www.pptfaq.com
> PPTools: www.pptools.com
> ================================================
>
>
>

 
Reply With Quote
 
theintern
Guest
Posts: n/a
 
      14th Jul 2008
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


"Steve Rindsberg" wrote:

> In article <F5474780-45D8-4143-AC02-(E-Mail Removed)>, Theintern
> wrote:
> > 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?

>
> What's the exact error message you get.
>
> And have you tried firing a sub in your addin from within the event handler
> class:
>
> ByeBye
>
> Public Sub ByeBye()
> Application.Quit
> End Sub
>
> -----------------------------------------
> Steve Rindsberg, PPT MVP
> PPT FAQ: www.pptfaq.com
> PPTools: www.pptools.com
> ================================================
>
>
>

 
Reply With Quote
 
theintern
Guest
Posts: n/a
 
      16th Jul 2008
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

"Steve Rindsberg" wrote:

> I'm not clear on what you put where ...
>
> I'm thinking you need an addin project with at least one regular basic module and
> one class.
>
> The bas module contains your CreateShow code and the "byebye" sub, plus whatever
> other code you need.
>
> The class contains just the event handler code. The PresentationOpen event should
> call your CreateShow code and the end show event should call ByeBye.
>
> See how that works ...
>
> In article <38E7143E-4C50-41DA-92B1-(E-Mail Removed)>, Theintern wrote:
> > 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
> >
> > "Steve Rindsberg" wrote:
> >
> > > In article <F5474780-45D8-4143-AC02-(E-Mail Removed)>, Theintern
> > > wrote:
> > > > 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?
> > >
> > > What's the exact error message you get.
> > >
> > > And have you tried firing a sub in your addin from within the event handler
> > > class:
> > >
> > > ByeBye
> > >
> > > Public Sub ByeBye()
> > > Application.Quit
> > > End Sub
> > >
> > > -----------------------------------------
> > > Steve Rindsberg, PPT MVP
> > > PPT FAQ: www.pptfaq.com
> > > PPTools: www.pptools.com
> > > ================================================
> > >
> > >
> > >

> >

>
> -----------------------------------------
> Steve Rindsberg, PPT MVP
> PPT FAQ: www.pptfaq.com
> PPTools: www.pptools.com
> ================================================
>
>
>

 
Reply With Quote
 
theintern
Guest
Posts: n/a
 
      16th Jul 2008
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 <B8024722-4004-4BA7-827C-(E-Mail Removed)>, 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
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Save, close, reopen a presentation from within an event handler Shyam Pillai Microsoft Powerpoint 0 19th Aug 2009 03:59 PM
RE: Save, close, reopen a presentation from within an event handler Cosmo Microsoft Powerpoint 0 19th Aug 2009 03:36 PM
close from event handler or presentationopen fire every time theintern Microsoft Powerpoint 1 15th Jul 2008 05:01 PM
adding a event handler in MFC application for c# event Mayur Gadhave Microsoft VC .NET 2 30th Aug 2006 08:14 AM
need Document Close event handler Eric Li Microsoft C# .NET 2 28th May 2004 06:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:35 PM.