Resolved: What if the file i want to delete has already been deleted ("kill" macro)?

MickFlanagen

New Member
Joined
Jan 24, 2012
Messages
27
I'm using the following macro:

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)

Kill "T:\usequty\Audit Reporting\T-Cross Reports\tcross.xls"

End Sub
The marco is working well, but it is very possible that the file has already been deleted. In such cases, I do not want the error to come up. Is there a way to tell excel "if this file exists, delete it. If not, just close"?

Thanks for the help

Mick
 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Re: What if the file i want to delete has already been deleted ("kill" macro)?

Possibly

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)

If Dir("T:\usequty\Audit Reporting\T-Cross Reports\tcross.xls") <> "" Then Kill "T:\usequty\Audit Reporting\T-Cross Reports\tcross.xls"

End Sub
 
Upvote 0
Re: What if the file i want to delete has already been deleted ("kill" macro)?

This might work for you.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> checkfile1()<br><SPAN style="color:#007F00">'Use the dir to check if the file exist in the folder</SPAN><br><SPAN style="color:#00007F">If</SPAN> Dir("T:\usequty\Audit Reporting\T-Cross Reports\tcross.xls") <> "" <SPAN style="color:#00007F">Then</SPAN><br>    Kill "T:\usequty\Audit Reporting\T-Cross Reports\tcross.xls"<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
Re: What if the file i want to delete has already been deleted ("kill" macro)?

That seems to have fixed it, much appreciated

Mick
 
Upvote 0

Forum statistics

Threads
1,215,500
Messages
6,125,166
Members
449,210
Latest member
grifaz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top