Save As to automatically overwrite an existing file

grahamiwa

New Member
Joined
Mar 14, 2011
Messages
30
I have a Save As statment in a macro that saves a copy of the file to a different folder with the days date inserted in the file name. It works fine.

If there is already a copy of the file in that folder with the same file name I get the normal message box asking if I want to replace the file with the one I an trying to save.

Is there a way to inhibit this message box appearing and automatically overwrite any existing file with the newer version.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Bound the save command with

Application.DisplayAlerts = False
CODE
Application.DisplayAlerts = True
 
Upvote 0
My VB knowledge & Skills are not great at the moment so I rely on tons of help from this forum whie I learn

The code I currently have which works the way I want is

Dim strFileName As String

strFileName = "\\mlbdat02\shared\organization\T&D-All\ePTW Course Scheduling\ePTW Schedule Master\ePTW Schedule Master R1" & Chr(32) & Format(Date, "d mmm yyyy") & ".xls"
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p> </o:p>
MsgBox "Saving File"

ActiveWorkbook.SaveAs Filename:=strFileName, FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
ActiveWorkbook.Close

I assume that I can delete the MsgBox "Saving File" and add the additional code on the line before ActiveWorkbook.Close so it will look like this

Dim strFileName As String

strFileName = "\\mlbdat02\shared\organization\T&D-All\ePTW Course Scheduling\ePTW Schedule Master\ePTW Schedule Master R1" & Chr(32) & Format(Date, "d mmm yyyy") & ".xls"

ActiveWorkbook.SaveAs Filename:=strFileName, FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False

Application.DisplayAlerts = False
CODE

Application.DisplayAlerts = True

ActiveWorkbook.Close


Did I get this right??
 
Upvote 0
No. "CODE" was where your saveas code goes.

Code:
Dim strFileName As String

strFileName = "\\mlbdat02\shared\organization\T&D-All\ePTW Course Scheduling\ePTW Schedule Master\ePTW Schedule Master R1" & Chr(32) & Format(Date, "d mmm yyyy") & ".xls"
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=strFileName, FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
Application.DisplayAlerts = True

ActiveWorkbook.Close
 
Upvote 0
I turned my brain on after the second try :biggrin: and realised the CODE meant my "SaveAs" code

It works perfectly

My thanks :)
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top