Excel: QUIT Function Returns Macro Error if Cancel Selected

Last reviewed: November 30, 1994
Article ID: Q63809
The information in this article applies to:
  • Microsoft Excel forWindows, versions 3.0, 4.0
  • Microsoft Excel forthe Macintosh, versions 2.2, 3.0, 4.0

SUMMARY

In Microsoft Excel, when the QUIT function is executed, a dialog box appears for each document that is open and has been changed. If Cancel is selected, a macro error appears, indicating the cell on the macro sheet in which the QUIT function is located.

The QUIT function is equivalent to choosing the Quit command from the File menu in Microsoft Excel for the Macintosh or the Exit command from the File menu in Microsoft Excel for Windows. If Cancel is selected, the Quit operation is aborted, thus producing a macro error.

To avoid this error, you can modify the macro to be sure that all documents are saved before executing the QUIT function. Another option is to use the CLOSE function to close all open documents (except the macro sheet that contains the running macro).

For example, the following macro closes all open documents. If the document has been changed, the standard dialog box appears, prompting you to save your changes. If you choose Cancel, the macro alerts you that Yes or No must be chosen instead and executes the CLOSE function again. It then saves the macro sheet and quits from Excel. The macro sheet is named "Macro1".

  A6: =IF(COUNTA(DOCUMENTS())>1,IF(GET.DOCUMENT(1)="Macro1",
      ACTIVATE.NEXT()),GOTO(A11))
  A7: =CLOSE()
  A8: =IF(A7,GOTO(A6),ALERT("Please choose either Yes or No when
      prompted to save changes."))
  A9: =GOTO(A6)
 A10: =SAVE()
 A11: =QUIT()

MORE INFORMATION

This information also applies to Excel for Windows versions 3.0 and 4.0.


KBCategory: kbusage
KBSubcategory:

Additional reference words: 2.2 2.20 3.0 3.00 4.0 4.00


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 30, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.