vba delete files in folder code example
Example 1: vba delete file
Function FileExists(ByVal FileToTest As String) As Boolean
FileExists = (Dir(FileToTest) <> "")
End Function
Sub DeleteFile(ByVal FileToDelete As String)
If FileExists(FileToDelete) Then
SetAttr FileToDelete, vbNormal
Kill FileToDelete
End If
End Sub
Example 2: excel vba delete folder
Sub DeleteFolder(pFolder As String, pDeleteReadOnlyToo As Boolean)
Dim FSO As New FileSystemObject
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.DeleteFolder pFolder, pDeleteReadOnlyToo
End Sub