Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Kill statement not works

Status
Not open for further replies.

stranger123

Programmer
Apr 16, 2006
76
GB
Hi,

In Excel VBA, I tried
Kill "C:\xxxxx\xxx.txt"
without success with no error message. Why?
I know the path is currect and the file is existed.
 
There are two possibilities here:

1. Your Excel macro security permissions are set to high, so they won't run. Check this from Tools -> Macro -> Security and ensure it is set to Medium.
Reopen the workbook and choose Enable the file.

2. The second possibility is that your user account doesn't have permission to delete the file from the disk.

It will need NTFS Modify permissions or a custom setting with the Delete File/Folder permission.
You can check this on the right click properties menu of the file or containing folder on the Security tab.

John
 
jrbarnett,

Thank you for your comments.
I have just check the "Security" and found it is set to Medium.
I can delete the files by "Kill" in Visual Basic 6.0.
 
There is a third thing I forgot to mention - that the file itself must not be open at the time you want to delete it. Presumably this is the case.

If you can delete the file in VB6 (assuming this app is run by you) then your network or PC user account has permission to delete the file from disk.

Odd, I'll have a think and post back.

John
 
If the file is open then I would expect this to generate a runtime error.

I would also expect a runtime error if the account doesn't have the appropriate permissions to delete from the directory.

Try setting your macro security level to low.

Ed Metcalfe.

Please do not feed the trolls.....
 
Hi,

another thing you might want to check is if VBA is a trusted source.

Tools --> Macro --> Security --> tab: Trusted Sources --> Trust Access to Visual Basic Project

that's the bottom checkbox. It needs to be checked.

Although, I would also expect to see an error of some sort for all of the above except maybe the security level.

Cheers,

Roel
 
Is this part of a larger code? If so, post it all please.

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Hi guys. I'm actually having a similar problem that's driving me nuts. When the Kill statement executes, nothing happens. I'm creating an HTML file in the root of C: for the purposes of copying its contents to an Outlook email. When I'm done, I wanted to delete the file just to clean it up, but nothing is happening. In fact, I've noticed that the app appears to just die on that statement altogether. I've one more statement after it, and that statement doesn't get executed if the Kill statement is there.

Code:
    ' remove the temp html file
    Kill "C:\tempsht.htm"

    ' delete the temporary range created in the output sheet
    OutFile.Range("A5000:J5012").Delete

In the above code, the .Delete statement never executes because the program dies on the Kill statement (how ironic). I've put breakpoints on both statements to be sure.

The file definitely exists, and is spelled correctly, etc.
 
Ok, so I figured out what was happening. I was opening the file for textstream reading and it wasn't closing it. Once I closed the textstream, I was able to Kill the file successfully. It's too bad I never got an error to give me some indication as to what was happening. Oh well. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top