ByPassing Do You Want To Overwrite The File Message Box

Simba1

Board Regular
Joined
Dec 13, 2004
Messages
165
Hi guys,

I've created a macro that saves a copy of my file to a specific location once the workbook is closed. I've encountered a problem if the user saves the file twice in the same day - it asks if I want to replace the previous version - I just want it to save or overwrite the file.

Can anyone look at my code and advise me on how I can bypass the Msgbox that pops up saying "A File named xxx.xls already exists in this location. Do you want to replace it?" I get an error if I press Cancel or No. What I want to do is have it overwrite the file without any prompt or confirmation.

Thanks

*The Call DeleteMenu is not needed here...its for another function I made.
Code:
Sub Workbook_BeforeClose(Cancel As Boolean)
    Call DeleteMenu
    ActiveWorkbook.SaveAs Filename:="G:\PUBLIC\Demand Planning\Backup of DP Reports\PRODUCT MASTER" & Format(Now(), "ddmmyy") & ".xls"
    Application.DisplayAlerts = False
    ActiveWorkbook.Close
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Richie(UK)

MrExcel MVP
Joined
May 17, 2002
Messages
3,329
Hi,

Add the line:

Application.DisplayAlerts=False

before the save instruction and then switch back to True again when done.

HTH
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,836
Messages
5,766,714
Members
425,373
Latest member
ndiejennrrd

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