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.
 

Some videos you may like

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Airfix9

Well-known Member
Joined
Sep 23, 2005
Messages
886
Bound the save command with

Application.DisplayAlerts = False
CODE
Application.DisplayAlerts = True
 

grahamiwa

New Member
Joined
Mar 14, 2011
Messages
30
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??
 

Airfix9

Well-known Member
Joined
Sep 23, 2005
Messages
886
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
 

grahamiwa

New Member
Joined
Mar 14, 2011
Messages
30
I turned my brain on after the second try :biggrin: and realised the CODE meant my "SaveAs" code

It works perfectly

My thanks :)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,514
Messages
5,596,612
Members
414,080
Latest member
penguin23

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
Top