Added Kill Statement results in error

Bridgetree

New Member
Joined
Jun 1, 2005
Messages
19
I have a macro that imports a bunch of flat files into separate worksheets in another workbook then at the end activates the original workbook containing the macro and closes it like this:

Windows("ORIGINALFile.xls").Activate
ActiveWorkbook.Close False

All I did was add a KILL statement before the close to delete all the flat files like this:

KILL "c:\folder1\folder2\filena*"
Windows("ORIGINALFile.xls").Activate
ActiveWorkbook.Close False

and now I get an error on the activate. I don't have a very good VBA reference so I'm not sure I'm doing it with the correct commands? Can anyone help me with why it worked before the KILL statement was added and now doesn't?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi

Have you closed all the flat files before trying to run the KILL statement?

Tony
 
Upvote 0
Sorry it took me so long to get back to this. I am assuming that all the files are closed since I had also tried the Kill Statement alone. Is there a command to use to make sure they are all closed?
 
Upvote 0
Try the following. It will close all files except the original file, delete the selected files and then close the original file.

For Each w In Workbooks
If w.Name <> "ORIGINALFile.xls" Then
w.Close savechanges:=False
End If
Next w
KILL "c:\folder1\folder2\filena*"
Workbooks("ORIGINALFile.xls").Activate
ActiveWorkbook.Close False
 
Upvote 0

Forum statistics

Threads
1,207,097
Messages
6,076,556
Members
446,213
Latest member
bettigb

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