VBA Delete Folder with DeleteFolder (FSO)

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on July 19, 2021

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!

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples