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

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

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
 

Forum statistics

Threads
1,148,048
Messages
5,744,501
Members
423,881
Latest member
Nguyen Vu

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