MXL5: Application.Quit in Auto_Open Sub Causes Computer to Hang

ID: Q129434


The information in this article applies to:
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a
  • Microsoft Excel for the Power Macintosh, versions 5.0, 5.0a


SYMPTOMS

In the versions of Microsoft Excel listed at the beginning of this article, if you open a workbook that contains an Auto_Open subroutine that contains the following line of code


   Application.Quit 
Microsoft Excel may stop responding (hang) with either a type 1 error or a type 11 error, depending on whether you are running Microsoft Excel for the Macintosh or Microsoft Excel for the Power Macintosh.


WORKAROUND

To work around this problem, do either of the following:

  • Do not use Application.Quit in the Auto_Open subroutine


  • -or-

  • Instead of using a single Auto_Open subroutine, include an Application.OnTime command in your Auto_Open subroutine. This command should be set up in such a way that it executes another subroutine after the Auto_Open subroutine has completed execution. This other subroutine contains the Application.Quit command.
    For example, instead of using this
    
             Sub Auto_Open()
                 MsgBox "This is a test."
                 Application.Quit
             End Sub 
    use this:
    Sub Auto_Open()
                 Application.OnTime Now + TimeValue("00:00:02"), "QuitMSExcel"
             End Sub
    
             Sub QuitMSExcel()
                 MsgBox "This is a test."
                 Application.Quit
             End Sub 
    Using Application.OnTime to indirectly call the subroutine containing Application.Quit allows you to avoid hanging your computer. If the Auto_Open subroutine contains Application.Quit, or if the Auto_Open subroutine directly executes a macro that contains the Application.Quit command, your computer will hang.



STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. This problem was corrected in Microsoft Excel 98 Macintosh Edition.


MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
The following is an example of an Auto_Open subroutine that will cause Microsoft Excel 5.0 to hang when the workbook that contains it is opened:

   Sub Auto_Open()
       Application.Quit
   End Sub 
If you open a workbook that contains this subroutine, you will receive one of the following error messages:
The application "unknown" has unexpectedly quit, because an error of type 1 occurred.
-or-
Sorry, a system error occurred.
"Microsoft Excel"
error type 11
and the computer will either restart or hang when you select the Restart button.

This error will not occur unless the subroutine is an Auto_Open subroutine. For example, when you run the following subroutine

   Sub Test()
       Application.Quit
   End Sub 
an error will not occur unless the Test subroutine is directly called by an Auto_Open subroutine.

Additional query words: 5.00a auto open autoopen exit hang lock

Keywords : kbcode kbprg xlmac
Version : MACINTOSH:5.0,5.0a
Platform : MACINTOSH
Issue type : kbprb


Last Reviewed: November 9, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.