How can I stop the prompt for saving an existing file when copying data from excel sheet?

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
171
Office Version
  1. 365
Platform
  1. Windows
I have the following code:

VBA Code:
Sub addwb()

    Application.ScreenUpdating = False

    Dim wbNew As Workbook

    Sheet1.Copy
    
    Set wbNew = ActiveWorkbook
    
    wbNew.SaveAs "C:\Users\Owner\Documents\Automation\TestWB.xlsx", 51
    
    wbNew.Close True


End Sub

but I am prompted if I want to overwrite the existing file. How can I make it force the save and not ask the user for a confirmation?
 

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,)
Application.DisplayAlerts = False
One addition to this beautiful but dangerous method of the Application object: Always enable it after you are done using it in your code. It might cause unwanted results otherwise since it will disable all other alerts.

VBA Code:
Application.DisplayAlerts = False
' Do what you need
Application.DisplayAlerts = True
 
Upvote 0
One addition to this beautiful but dangerous method of the Application object: Always enable it after you are done using it in your code. It might cause unwanted results otherwise since it will disable all other alerts.

VBA Code:
Application.DisplayAlerts = False
' Do what you need
Application.DisplayAlerts = True
If I have the Application.DisplayAlerts = False on a close workbook event, does it not default back to true when opening the file?
 
Upvote 0
If I have the Application.DisplayAlerts = False on a close workbook event, does it not default back to true when opening the file?
It works only when the macro is working, and Excel sets it as True as soon as the macro is finished. The danger I mentioned was about forgetting it in the False state might suppress other alerts that you might need to see until the macro is finished.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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