deleting/overwriting an excelfile

  • Thread starter Thread starter walt
  • Start date Start date
W

walt

Hi, I am using the following command to create a new excel file named
"Log.xls" (RetStr is defined above in the macro...)

Dim dummy As String
dummy = RetStr + "\Log.xls"

Set newBook = Workbooks.Add
With newBook
.Title = "ErrorLogs"
.SaveAs Filename:=dummy
End With

That works very good. But i need a routine that checks if the file already
exists. And if so, delete/overwrite that file before creating it (again).

Any hints?

TIA Walt
 
Set newBook = Workbooks.Add
With newBook
.Title = "ErrorLogs"
Application.DisplayAlerts = False
.SaveAs Filename:=dummy
Application.DisplayAlerts = True
End With



Regards,
Tom Ogilvy
 
I prefer to use something that check if it is already open
and then close it,
On Error Resume Next
Dim dummy As String
dummy = RetStr + "\Log.xls"
Workbooks("Log.xls").Close False
Set newBook = Workbooks.Add
With newBook
.Title = "ErrorLogs"
Application.DisplayAlerts = False
.SaveAs Filename:=dummy
Application.DisplayAlerts = True
End With


Francisco Mariscal
fcomariscal at hotmail dot com
 
Back
Top