Monday, October 22, 2012

How to Delete Whole Folder With All Files using VBA Macro

Excel VBA Macro to Delete Whole Folder With All Files
Sub Delete_Whole_Folder()
    Dim FSO As Object
    Dim MyPath As String

    Set FSO = CreateObject("Scripting.FileSystemObject")

    MyPath = "C:\Documents and Settings\Administrator\My Documents\Sample"
'Sample is the Folder to Delete
    If Right(MyPath, 1) = "\" Then
        MyPath = Left(MyPath, Len(MyPath) - 1)
    End If

    If FSO.FolderExists(MyPath) = False Then
        MsgBox MyPath & " Folder Doesn't Exist In Given Path", , "Filder Does Not Exist"
        Exit Sub
    End If

    FSO.DeleteFolder MyPath

End Sub

Thanks,Tamatam

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.