Update macro to just auto overwrite if file name already exists

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,679
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi everyone,
This macro works great, but if there is already a file with the same name it dugs out,
i want it to just overwrite the file.
can this be done?
if so, lease update the attached.
thanks
Tony

my code
VBA Code:
Sub Create_Report()
 Call AA_Protect
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False


myLoc = Application.ActiveWorkbook.Path
NewName = Range("O10")

ActiveSheet.Copy

ActiveWorkbook.SaveAs myLoc & "\" & NewName & ".xlsx"

MsgBox "Report Created"


Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
 Call AA_unProtect
End Sub
 

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,974
Office Version
  1. 365
Platform
  1. Windows
Turning off alerts with this line of code:
VBA Code:
Application.DisplayAlerts = False
should suppress those warnings.

Are you sure that isn't a different issue, such as the file with the same name that you want to overwrite is already open on your computer or someone else's (you cannot overwrite an open file)?
Or that you have an invalid file name in cell O10 (what value exactly is in this cell)?

What is the exact message you are getting?
 

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,679
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Joe,
I thought i had I'll try it again
thanks
Tony
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,974
Office Version
  1. 365
Platform
  1. Windows
If it still does not work, please provide us with the value in cell O10 and let us know the exact message you are getting.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,402
Messages
5,601,475
Members
414,452
Latest member
Dannysamworth

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