if workbooks exists delete

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!
 
A

AB

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
 
J

Jim Thomlinson

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
 
S

Stephen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top