5/5/24, 10:55 PM VBA CopyFile - FileSystemObject - Copy Files in Excel VBA
Analyst Cave
Home » VBA FileSystemObject (FSO) in Excel – Methods and Properties » VBA CopyFile
VBA CopyFile
The FileSystemObject VBA CopyFile method copies one or more files from one a source
to a destination location.
VBA FileSystemObject Methods
BuildPath CopyFile CopyFolder CreateFolder CreateTextFile DeleteFile DeleteFolder
DriveExists FileExists FolderExists GetAbsolutePathName GetBaseName GetDrive
GetDriveName GetExtensionName GetFile GetFileName GetFolder
GetParentFolderName GetSpecialFolder GetTempName MoveFile MoveFolder
OpenTextFile
VBA COPYFILE SYNTAX
1 fso.CopyFile source, destination, [ overwrite ]
source
The source location of the file or files. You can use wildcards such as *.* to specify more
than a single file matching the pattern.
destination
The destination location (folder) where the source files are to be copied to.
overwrite
Optional. If True will overwrite files with same name in destination folder. If True it will
omit files for which there is an existing filename in the destination folder.
VBA COPYFILE EXAMPLES
1 Set fso = CreateObject("Scripting.FileSystemObject")
2
3 'Copy just the Hello.xlsx file
4 fso.CopyFile "c:\Src\Hello.xlsx", "c:\Dest\"
5
https://analystcave.com/vba-filesystemobject-fso-in-excel/vba-copyfile/ 1/2
5/5/24, 10:55 PM VBA CopyFile - FileSystemObject - Copy Files in Excel VBA
6 'Copy all files with XLSX extension to destination folder
7 fso.CopyFile "c:\Src\*.xlsx", "c:\Dest\"
8
9 'Copy all files to destination folder
10 fso.CopyFile "c:\Src\*.*", "c:\Dest\"
11
12 'Copy all files in subfolders of C:\Src to destination folder
13 fso.CopyFile "C:\Src\*\*.*", "c:\Dest\"
https://analystcave.com/vba-filesystemobject-fso-in-excel/vba-copyfile/ 2/2