How to Replace Existing Excel File

  • Thread starter Thread starter Bruce Bates
  • Start date Start date
B

Bruce Bates

Please help, I'm trying to save a worksheet to a CSV file. The following
code works but requires the user to select "Yes"to replace the existing
file. What do I need to include to automatically overwrite the file with the
new one.

Thanks for any help.
Bruce Bates

ActiveWorkbook.SaveAs Filename:="Ngatapa", FileFormat:= _
xlCSV, CreateBackup:=False


ActiveWorkbook.Saved = True
ActiveWorkbook.Close
 
Hi Bruce
Wrap the saveas line as follows...

Application.DisplayAlerts = False

ActiveWorkbook.SaveAs Filename:="Ngatapa", FileFormat:= _
xlCSV, CreateBackup:=False

Application.DisplayAlerts = True

Cheers
Nigel
 
Same topic - another question:

I do not want my macro to overwrite, so I have the DisplayAlerts=True
The problem is when I answer "No" to the question if I want to replace
I get run-time error.

Thanks in advance,
Erlend

filetypes = "Text files (*.txt),*.txt,All files (*.*),*.*"

filename = "C:\bbar\" & name & ".txt"
fn = Application.GetSaveAsFilename(InitialFilename:=filename
Filefilter:=filetypes, FilterIndex:=1)

If fn = False Then Exit Sub

ActiveWorkbook.SaveAs Filename:=fn, FileFormat:= _
xlText, CreateBackup:=Fals
 
Back
Top