December 4th, 2012, 10:12 AM
Permission Denied When Trying To Delete A File
I'm using the following code to copy some lines from file into a new file. After all the correct lines are copied, I delete the old file. This was working just fine last week. But suddenly it's not working on several computers and I don't know why it's not working.
It fails on the Kill (from_name) line. It says that it doesn't have permission. I'l closing the file before killing, so I don't know what the issue is.
Public Function DeleteLines(ByVal from_name As String, ByVal to_name As String, ByVal target As String) As Long
Dim strlen As Integer
Dim from_file As Integer
Dim to_file As Integer
Dim one_line As String
Dim deleted As Integer
' Open the input file.
from_file = FreeFile
Open from_name For Input As from_file
' Open the output file.
to_file = FreeFile
Open to_name For Output As to_file
' Copy the file skipping lines containing the
deleted = 0
Do While Not EOF(from_file)
Line Input #from_file, one_line
If InStr(one_line, target) > 0 Then
Print #to_file, one_line
deleted = deleted + 1
' Close the files.
MsgBox ("before kill")
MsgBox ("after kill")
Name to_name As from_name
DeleteLines = deleted
Anyone have any ideas?
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.