![]() |
deleting/overwriting an excelfile
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 |
deleting/overwriting an excelfile
Set newBook = Workbooks.Add
With newBook .Title = "ErrorLogs" Application.DisplayAlerts = False .SaveAs Filename:=dummy Application.DisplayAlerts = True End With Regards, Tom Ogilvy "walt" wrote in message ... 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 |
deleting/overwriting an excelfile
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 -----Original Message----- Set newBook = Workbooks.Add With newBook .Title = "ErrorLogs" Application.DisplayAlerts = False .SaveAs Filename:=dummy Application.DisplayAlerts = True End With Regards, Tom Ogilvy "walt" wrote in message ... 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 . |
All times are GMT +1. The time now is 05:06 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com