Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    AutoExit Macro (WORD 97/2000)

    I have defined my own AutoExit macro (plus other such AutoClose, AutoNew, AutoOpen, FileSave, FileSaveAs ...).

    The problem that my AutoExit macro is NOT being invoked when I close WORD (by clicking on 'X'). WORD display the normal do you want to save file xxx etc and continues to do its own thing.

    Anyone, any ideas please. Getting desperate now. Thanks.
    Thanks.
    Robie

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: AutoExit Macro (WORD 97/2000)

    You need to switch to document events:
    1. <LI>From Word, press <Alt><F11> to go to the VBE
      <LI>In the upper-left Project Explorer window, double click the ThisDocument icon under your document
      <LI>In the new code window, press the Object drop-down and select Document
      <LI>Press the Procedure drop-down and select Close
      <LI>At the top enter "Option Explicit"
      <LI>Copy the code from your AutoOpen and AutoClose into this skeleton
      <LI>Repeat the above in the Normal | Microsoft Word Objects | ThisDocument and replace your AutoNew.
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: AutoExit vs. Application_Quit

    The document events available in ThisDocument are: New, Open, and Close. This still won't provide for an autoexit event.

    I've read in the past that there is no easy way to trap the "close app via clicking on 'X' event' - but have just played around with the Application.Quit event and it does seem to work. (Not sure, but this may not be available in Word 97.)

    What needs to be done: you need to have a global template that is in the Startup directory, so that it is always running when Word is running.

    Put a standard code module in this global template.
    At the beginning of the standard module (before any procedures), put something like:

    Public AppEvents As New clsAppEvents

    Now below this put a procedure like this:

    Sub AutoExec()
    Set AppEvents.App = Word.Application
    End Sub

    This will automatically create a new application-level object, every time Word is launched.

    Now, in this same global template, add a class module. Rename the module "clsAppEvents" (i.e. it needs to have the same name as was used in the Public declaration at the beginning of the standard module).

    At the top of this class module (i.e. before any procedures), put the following statement:

    Public WithEvents App As Word.Application

    And below this, add the following procedure:

    Private Sub App_Quit()
    MsgBox "Did we trap the Quit event?" '(this is just a test)
    'You can put whatever code you want here
    End Sub

    If you put the above into place, it should trap all application close events, including clicking on the "X".

    Gary

Posting Permissions

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