ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   if workbooks exists delete (https://www.excelbanter.com/excel-programming/437012-if-workbooks-exists-delete.html)

Stephen

if workbooks exists delete
 
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!

AB[_2_]

if workbooks exists delete
 
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


On 4 Dec, 14:40, Stephen wrote:
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!



Rick Rothstein

if workbooks exists delete
 
Look up the "Kill Statement" in VB's help files.

--
Rick (MVP - Excel)


"Stephen" wrote in message
...
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!



Jim Thomlinson

if workbooks exists delete
 
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
--
HTH...

Jim Thomlinson


"Stephen" wrote:

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!


Stephen

if workbooks exists delete
 
brilliant! thank you much!!!

"Jim Thomlinson" wrote:

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
--
HTH...

Jim Thomlinson


"Stephen" wrote:

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!



All times are GMT +1. The time now is 01:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com