TropicalMagic
New Member
- Joined
- Jun 19, 2021
- Messages
- 47
- Office Version
- 365
- Platform
- Windows
Hi, I would like to delete any and all .csv files in the same folder.
However, the code isn't working as there is a run-time error 53: "File not found" at the "Kill ThisFile" line.
Can anyone help me with the issue?
Many thanks!
However, the code isn't working as there is a run-time error 53: "File not found" at the "Kill ThisFile" line.
VBA Code:
Sub Delete_CSV_Files()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim MyFolderPath As String
Dim ThisFile As Variant
MyFolderPath = Application.DefaultFilePath
ThisFile = MyFolderPath & Dir(MyFolderPath & "\" & "*.csv", vbNormal)
While ThisFile <> ""
Kill ThisFile
ThisFile = MyFolderPath & Dir
Wend
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Can anyone help me with the issue?
Many thanks!