Microsoft KB Archive/65905

{| = SAVE.AS Returns Error if Replacing Existing? Dialog Canceled =
 * width="100%"|

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.

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(&quot;Save file as: (Ex.: Sheet1.XLS)&quot;,2,,GET.WINDOW(1)) A2: =IF(A1,,RETURN) A3: =FILES(A1) A4: =IF(ISERROR(A3),SAVE.AS(A1),GOTO(A6)) A5: =RETURN A6: =ALERT(&quot;File already exists. Overwrite it?&quot;,1) A7: =IF(A6,FILE.DELETE(A1),GOTO(A1)) A8: =SAVE.AS(A1) A9: =RETURN
 * }