Saturday, April 20, 2019

Deleting Folders in VBA Excel

Deleting Folders in VBA Excel


'In this Example I am Deleting "C:\SampleFolder"
Sub sbDeletingAFolder()

Dim FSO
Dim sFolder As String

sFolder = "C:\SampleFolder" 'Specify Your Folder Which You Wants to Delete
Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.FolderExists(sFolder) Then
FSO.DeleteFolder sFolder
MsgBox "Specified Folder Deleted Successfully", vbExclamation, "Done!"
Else
MsgBox "Specified Folder Not Found", vbExclamation, "Not Found!"
End If

End Sub

No comments:

Post a Comment