vba delete file

The solution for “vba delete file” can be found here. The following code will assist you in solving the problem.

‘ Needs to add “Microsoft Scripting Runtime” reference to your file
Function FileExists(ByVal FileToTest As String) As Boolean
FileExists = (Dir(FileToTest) <> “”)
End Function

Sub DeleteFile(ByVal FileToDelete As String)
If FileExists(FileToDelete) Then ‘See above
‘ First remove readonly attribute, if set
SetAttr FileToDelete, vbNormal
‘ Then delete the file
Kill FileToDelete
End If
End Sub

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

Similar Posts