Excel: QUIT Function Returns Macro Error if Cancel Selected

ID: Q63809


The information in this article applies to:


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.

Additional query words: 2.2 2.20 3.0 3.00 4.0 4.00


Keywords          : 
Version           : 
Platform          : 
Issue type        : 

Last Reviewed: March 21, 1999