Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default 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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default 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!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default 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!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If Pivot Table Exists, Delete on Close ryguy7272 Excel Programming 4 December 15th 08 12:10 PM
If sheet exists, delete Darin Kramer Excel Programming 2 August 20th 07 07:01 PM
Check for a shape - then change or delete it if it exists Mona-ABE Excel Programming 2 May 30th 07 05:37 PM
Copy from multiple workbooks, rename, and overwrite if exists [email protected] Excel Programming 4 February 19th 07 11:30 PM
If worksheet exists delete cereldine[_43_] Excel Programming 4 July 13th 06 05:26 PM


All times are GMT +1. The time now is 07:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"