Copy Specific Files or All Files from Source Folder to Destination Folder with VBA

How to copy specific files or all files from source folder to destination folder with VBA. In this solution we have used the File System Object or FSO for short.

What is FSO? It offers an easy object based model to access the file system on our computer. First we need to create an instance of FileSystemObject in VBA as shown in the code below. Now using FSO we can generate files, read files, copy or move files, delete files, check if folder exists and loop though folders and sub-folders. Below are given some interesting links for further study.

Watch the video below:


Watch this video on YouTube.

The following VBA code will copy all Excel files or files that you specify from a source folder to the specified destination folder:

Sub copy_specific_files_in_folder()
Dim FSO As Object
Dim sourcePath As String
Dim destinationPath As String
Dim fileExtn As String

sourcePath = “C:\exceltrainingvideos”
destinationPath = “C:\Users\takyar\test100\”

fileExtn = “*.xl*”

If Right(sourcePath, 1) <> “\” Then
sourcePath = sourcePath & “\”
End If

Set FSO = CreateObject(“scripting.filesystemobject”)

If FSO.FolderExists(sourcePath) = False Then
MsgBox destinationPath & ” does not exist”
Exit Sub
End If

If FSO.FolderExists(destinationPath) = False Then
MsgBox sourcePath & ” does not exist”
Exit Sub
End If

FSO.CopyFile Source:=sourcePath & fileExtn, Destination:=destinationPath
MsgBox “Your files have been copied from ” & sourcePath & ” to ” & destinationPath

End Sub


Note: before you start using the File Object Systen or FSO in VBA you need to activate a reference of Microsoft Scripting Runtime Library as shown in the images below:

  1. Click on Tools in the Microsoft Visual Basic for Application Windows. Select References…
Reference to FSO
Reference to FSO

2. Activate Microsoft Scripting Runtime Library

Activate Microsoft Scriptung Runtime Library
Activate Microsoft Scripting Runtime Library


Further reading:

FileSystemObject in VBA – Explained

Accessing Files with FileSystemObject


Published by

Dinesh Kumar Takyar

Welcome to! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: For a structured Excel VBA training course online you can visit:

4 thoughts on “Copy Specific Files or All Files from Source Folder to Destination Folder with VBA”

  1. Hi,

    Thanks for the VBA code ,it works.
    Can you please provide the code extension so that it can help in searching in the subfolders also which are there in the source path

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.