Monday, 22 October 2012

How to Delete Whole Folder With All Files

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 Patah", , "Filder Does Not Exit"
        Exit Sub
    End If

    FSO.DeleteFolder MyPath

End Sub

2 comments:

  1. Well, very nice and most useful information collection, i think this coding will become more helpful for the all computer users. Keep sharing.
    powerpoint training

    ReplyDelete
  2. actually i need to delete folder and subfolder which contain files. If u post any coding regarding this, it vil more helpful for me. I already tried RmDir and MkDir command it doesn't work. is there any option to delete folder other than FSO method. this s my mail id vvvenkatbe@gmail.com

    ReplyDelete

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts