Saturday, 20 December 2014

Microsfot Excel - Macro - How to delete file

Watch this example on YouTube

Simple example that shows how to delete file using vba

The following code will delete file

Sub DeleteFile()
    Dim FileSystem
    Dim FileName As String
    FileName = "C:\Temp\ExcelTest\DelteMe.txt"
    Set FileSystem = CreateObject("Scripting.FileSystemObject")
    If FileSystem.FileExists(FileName) Then
        FileSystem.DeleteFile FileName, True
    Else
        MsgBox "Display Error", vbInformation, "Error"
    End If
End Sub

No comments:

Post a Comment