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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi,

Add the line:

Application.DisplayAlerts=False

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

HTH
 
Upvote 0

Forum statistics

Threads
1,222,180
Messages
6,164,419
Members
451,893
Latest member
csmithbuffalo

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