SAVE.AS Returns Error if Replacing Existing? Dialog Canceled

Last reviewed: November 2, 1994
Article ID: Q65905

SUMMARY

If you call the SAVE.AS function from a macro, you will receive a macro error if the Replace Existing? dialog box is canceled. This dialog warns you that the filename being used already exists in the active directory.

This problem was corrected in Microsoft Excel version 3.0.

MORE INFORMATION

Solution in Excel 2.x

The only way to eliminate this error, is to write a custom SAVE.AS function that checks whether the file exists, and deletes the file if it does. The following macro does this:

   A1: =INPUT("Save file as:  (Ex.: Sheet1.XLS)",2,,GET.WINDOW(1))
   A2: =IF(A1,,RETURN())
   A3: =FILES(A1)
   A4: =IF(ISERROR(A3),SAVE.AS(A1),GOTO(A6))
   A5: =RETURN()
   A6: =ALERT("File already exists. Overwrite it?",1)
   A7: =IF(A6,FILE.DELETE(A1),GOTO(A1))
   A8: =SAVE.AS(A1)
   A9: =RETURN()


KBCategory: kbother
KBSubcategory:

Additional reference words: noupd


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 2, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.