delete files

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am having a problem with the Kill Statement to delete files. Sometimes it finds the files and sometimes it does not. I am missing something in this macro? Is there a better way to delete files?
Thanks in advance for your help!

Here is the macro:

Private Sub CmdDelete_Click()
Dim path As String
path = ActiveWorkbook.Worksheets("4").Range("C1")
If TxtFileDelete.Text <> TxtReEnterfiletoDelete.Text Then
MsgBox ("File Name mismatch, please re-enter")
Else
ActiveWorkbook.Worksheets("4").Range("C1").Value = TxtReEnterProjtoDelete.Value
Kill (path)
End If

End Sub
 
Myriam wrote...
I am having a problem with the Kill Statement to delete files.
Sometimes it finds the files and sometimes it does not. I am
missing something in this macro? Is there a better way to delete
files? ...
Private Sub CmdDelete_Click()
Dim path As String
path = ActiveWorkbook.Worksheets("4").Range("C1")
If TxtFileDelete.Text <> TxtReEnterfiletoDelete.Text Then
MsgBox ("File Name mismatch, please re-enter")
Else
ActiveWorkbook.Worksheets("4").Range("C1").Value = _
TxtReEnterProjtoDelete.Value
Kill (path)
End If
End Sub

First off, if ActiveWorkbook.Worksheets("4").Range("C1") is eithe
TxtFileDelete or TxtReEnterfiletoDelete, use those tokens instead.

Next, programming questions should be asked in .programming rather tha
.worksheet.functions.

What error message, if any, is thrown when this macro fails to delet
'path', which comes from '4'!C1? Usually the main cause for Kill t
fail is that its pathname argument doesn't correspond *exactly* to an
file on any of your drives or shares. Have you made sure that th
'path' variable is *exactly* the same (down to the same placement an
number of embedded spaces) as the pathname of the file you're trying t
delete
 
Back
Top