Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trap App Close Event

    I know I've asked this before, but maybe not too clearly. I'd like to trap the Word Application Close (the top right X) clicked event (if there is such a thing). I know about application events as per Dave Rado and other MS documents explaining how to add application events with the WithEvents method. These don't work unless your instantiated oApp class object stays instantiated. If your set statement is in an AutoExec sub and that sub ends, there goes your application events processing. Such is the case with my app -- the Autoexec sub only runs to set up the Word session. And the UI portion of my app isn't always displayed so instantiating app events there does not good either. Is there an system event I can poll or trap using an API call? Anyone got an idea here?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Trap App Close Event

    Kevin,

    Help in the form API calls can be had from <A target="_blank" HREF=http://support.microsoft.com/support/kb/articles/Q192/7/33.ASP?>Q192733</A> - i think.

    Hope it's what you want

    Andrew

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trap App Close Event

    Andrew,

    That's very cool functionality, but I was looking for a way to trap that mouse click so my code executes first then ends with a

    Application.quit

    statement.

    You are definitely on to something here. Many thanks.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    kelliel
    Guest

    Re: Trap App Close Event

    I think you will find this of some help:

    <A target="_blank" HREF=http://msdn.microsoft.com/library/psdk/winui/keybacel_19t0.htm>http://msdn.microsoft.com/library/psdk/win...ybacel_19t0.htm</A>

    At least, that's where I would start.

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trap App Close Event

    Lawrence,

    I'm lost without examples. I have no idea how to implement that "message" to trap a click on the close button. Thanks, though, for thinking of me.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Trap App Close Event

    Kevin,

    If you require this for a particular document, would the document close event be any use, as it is triggered when the application is closed. Just a thought in the meantime.

    Andrew

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trap App Close Event

    Andrew, Lawrence, et al.?

    I've got the DocClose dialog "event" trapped and that works fine. I've also trapped the FileExit "event", but some users finish their Word session by Closing Word with the System Menu Close button -- which VBA apparently cannot trap directly. I have that old familiar problem of Word asking to save the template so I've trapped these dialogs/events to add the attachedtemplate.saved = true code to keep them from seeing the prompt. But those who use that Close button see the messages 'cause I can't trap that button. Your suggestion (and Q reference) to disable the button is my best be so far, but I would rather be able to put the code in some sub when that button is clicked.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trap App Close Event

    Andrew,

    BTW, the API code from the Q article to disable the Close button can be accomplished (as I have just discovered) in VBA directly with

    CommandBars("System").Controls("&Close").Visible = False

    A bit less overhead, heh?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trap App Close Event

    I take it back. I tested AFTER posting and though MS says it works, I can't get it to work. Back to the API code for now.

    <A target="_blank" HREF=http://support.microsoft.com/support/kb/articles/Q192/3/20.ASP>Q192320</A>
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  10. #10
    kelliel
    Guest

    Re: Trap App Close Event

    Ok, here is another page that you can try.

    <A target="_blank" HREF=http://msdn.microsoft.com/library/periodic/period99/VB99G15.HTM>http://msdn.microsoft.com/library/periodic...d99/VB99G15.HTM</A>

    After about 2 hours working on this, I am going to put it up for the night. For some reason, the wife (of nearly 25 years) wants some attention. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    More tomorrow.

  11. #11
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trap App Close Event

    Larry, (may I call you "Larry"?)

    This looks really good, and I thank you for taking the time to look this up for me. It looks like a lesson I'm overdue for learnin'.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  12. #12
    kelliel
    Guest

    Re: Trap App Close Event

    To me, API calls are one of the hardest aspects of VBA/VB programming; but, as in most everything, I suppose it is just a steep learning curve. In other words, once you know it, it is not that hard. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    About "Larry," Lawrence, please.

    Thanks

  13. #13
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trap App Close Event

    Lawrence it is! And thanks again.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  14. #14
    kelliel
    Guest

    Re: Trap App Close Event

    You know, I feel so dumb! I cannot believe how simple the answer.

    I mentioned your plight to our resident VB6 programmer (incredible programming for Access), and I mentioned trying to find the solution with API calls. She then said, "Well you can do that already in Word!"

    At that moment, I felt like: <img src=/S/bash.gif border=0 alt=bash width=35 height=39>

    The solution is so simple. You know that Word allows several Auto... procedures, right? Well there is an AutoExit procedure! Insert the following code in your normal.dot, or better yet a global template, and kick me into next week!

    <pre>Sub AutoExit()

    MsgBox "Intercepted"

    End Sub
    </pre>


    <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15>

    Frightful, isn't it.

  15. #15
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Trap App Close Event

    YOU feel dumb?

    And if I could show you my app, you would see I had already coded up an AutoExit sub. It's been there for some time. I completely forgot about it. I put it in a module called Shutdown, which has only that sub in it. Anyway, this may not all be good news: I had coded the AutoExit to prevent the user from seeing the prompt to save the template. And user's are still seeing the prompt. <img src=/S/mad.gif border=0 alt=mad width=15 height=15>

    That's what made me think, I needed to re-research a solution to this problem. Alas, the problem remains elusive. I recently "re-discovered" the .displayalerts property and will try that ----- IN THE AUTOEXIT!!!

    Many thanks, again.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •