Save As..but Filename already exist..howto Replace with YES? (1 Viewer)

alienscript

Registered User.
Local time
Today, 13:00
Joined
Jul 17, 2004
Messages
20
Hi the experts,

I was creating a Macro and face this SaveAs problem.. I illustrate with example below.

1) I already have a standard Excel file in C:\ as "Template.xls"
2) I recorded a macro on my excel "Template.xls" and copy-paste all the formulas as values and saved it as filename "Status (reviewed).xls"
3) I then re-type all the formulas in the active worksheet "Status (reviewed).xls" and saved it back in C:\ as "Template.xls"
4) then I stopped the macro recording.
5) I used Private Sub Workbook_Open() function in VB "ThisWorkbook"to auto-start the above macro in "Template.xls".
6) The macro auto-load works but before it could complete End Sub, it prompts me something like this: '"A file named 'C:\foldername\filename.xls' already exists in this location. Do you want to replace it ? It asks with three buttons -YES/NO/Cancel". The default button is at NO.

I had to click YES twice for the 2 SaveAs in order to continue the macro action. What should I add/change in the code to automatically continue by allowing YES ?

I attached the sample file. Please help me.
Thanks a lot in advance.
 

Attachments

  • SaveAs_butSameFileNameAlreadyExist_SetReplaceYES.zip
    96.3 KB · Views: 170

Adrianna

Registered User.
Local time
Today, 16:00
Joined
Oct 16, 2000
Messages
254
I know this is an old message, but no answer was posted. I didn't stop to actually download the zip file, but I ran into this issue borrowing a piece of someone elses code and just changed the action to .Save. There is no reason to use SaveAs, unless you really intend on offerring the ability to change the file name. So, as I have implemented,
If Condition is True Then
ThisWorkbook.SaveAs
Else
TheWorkbook.Save
End If
:) I hope that helps someone!
 

Users who are viewing this thread

Top Bottom