Question : How do I delete .txt files using VBA in Excel 2007?

I am using the following code to delete files. The code works to delete any file with a file extension other that .txt. I can delete .PDF, .DOC, & .XLS but cannot delete .txt files? What is the problem and how do I delete them? I am using Excel 2007 to run the code.

Private Sub Delete2()
Dim aFile As String
aFile = "\\.psf\Home\Documents\My PDFs\*.txt"
If Len(Dir$(aFile)) > 0 Then
  Kill aFile
End If
End Sub

Answer : How do I delete .txt files using VBA in Excel 2007?

Are you sure the files are actually .txt files? The name may have .txt at the end, but the actual file type is something else. Do you have "hide extensions for known file types" turned on in windows explorer? If you do, the file may actually be something like filename.txt.abc but will only show up as filename.txt.
Random Solutions  
 
programming4us programming4us