if workbooks exists delete

  • Thread starter Thread starter Stephen
  • Start date Start date
S

Stephen

Hi Folks,

I have a simple little problem where before my macro create a temp file by a
certain name, I want it to check if that file already exists and if it does,
delete it.

I have code that will delete the temp file as one of the finishing touches
on the procedure, but occasionally the program won't run all the way through
and upon autorecovery it needs user input asking if you want to overright the
existing file. I'd rather simply check for it and remove it if exists before
getting to that point.

TIA!
 
Function IsFileThere() As Boolean
Dim fso As Object

Set fso = CreateObject("Scripting.Filesystemobject")
If fso.FileExists("C:\CertainFileName.xls") Then' Your file name
goes there with full path
IsFileThere = True
Else
IsFileThere = False
End If

End Function
 
Try just setting
appliation.displayalerts = false

just prior to the save. Taht will stop the alert message. Set it back to
true when the save is complete

Application.DisplayAlerts = false
ThisWorkbook.SaveAs "C:\Tada.xls"
Application.DisplayAlerts = true
 
brilliant! thank you much!!!

Jim Thomlinson said:
Try just setting
appliation.displayalerts = false

just prior to the save. Taht will stop the alert message. Set it back to
true when the save is complete

Application.DisplayAlerts = false
ThisWorkbook.SaveAs "C:\Tada.xls"
Application.DisplayAlerts = true
 
Back
Top