VBA Copy a Folder with CopyFolder (FSO)

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on July 19, 2021

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

Copy 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.

Copying folders is easy with the CopyFolder method of the FileSystemObject.

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

    FSO.CopyFolder "C:\Src", "C:\Dst\" 'Dst folder exists 
    FSO.CopyFolder "C:\Src", "C:\DstNew" 'DstNew folder is created

End Sub

If source contains wildcard characters, or destination ends with a path separator (\), it is assumed that destination is an existing folder in which to copy matching folders and subfolders. Otherwise, destination is assumed to be the name of a folder to create.

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