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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permission denied when trying to Kill file

Status
Not open for further replies.

johngrg

Programmer
Apr 19, 2007
17
US
Excel 2003 vba

I'm getting Permission Denied error when trying kill existing file. What causes this, how can I delete an existing file that's on my hard drive? Thanks.

Code:
If Dir(mFileName) <> "" Then
Kill mFileName ' Kill the existing file
End If
 
Although you are doing this from VBA, this is not really a VBA issue and there are many possible causes.

First thing to ask is can you delete the file manually?

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
get the attributes in VBA so that you can decide if it is write protected or system etc. Spreadsheets that are open won't die.

There must be a way of detecting sharing but the only time I need that is over a VPN and it opens the spreadsheet then only the window title will give a clue eg read only in the text - maybe that is what I have to detect but it happens rarely so I haven't bothered yet.

there is a tide in the affairs of man that you Canute ignore.................
 
If that doesn't work, one of my coworkers had the same issue on her computer and asked for help. In the end, we discovered a Trojan horse had dug its way in her program files. Not saying that is what happened here, but it might be a possibility. Sorry if this didn't help.
 
Could be too simple but; Killing will fail if the target file is open.
 
As Hugh pointed out, the process was still running, and wouldn't let me Kill it. Thanks all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top