Return to VBA Code Examples

VBA Delete Folder with DeleteFolder (FSO)

This short tutorial will demonstrate how to use DeleteFolder method of the FileSystemObject.

Delete Folder with VBA FileSystemObject

This lesson uses the FileSystemObject. In order to use it, you will need to set a reference to the VB script run-time library. See here for more information.

Deleting folders is easy using DeleteFolder method of the FileSystemObject.

Sub FSODeleteFolder()
    Dim FSO As New FileSystemObject
    Set FSO = CreateObject("Scripting.FileSystemObject")

    FSO.DeleteFolder "C:\TestFolder", False

End Sub

If the optional ’force’ part at the end of the FSO.DeleteFolder line is set to True, folders with the read-only attribute set can be also deleted.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!