The FileSystemObject VBA CopyFolder method copies one or more folders 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 CopyFolder Syntax
fso.CopyFile source, destination, [ overwrite ]
source
The source location of the folders. You can use wildcards such as *.* to specify more than a single folder matching the pattern.
destination
The destination location (folder) where the source folders are to be copied to.
overwrite
Optional. If True will overwrite folders with same name in destination folder. If True it will omit folders for which there is an existing folder in the destination folder.
VBA CopyFolder Examples
Set fso = CreateObject("Scripting.FileSystemObject") 'Copy just the Hello folder fso.CopyFolder "c:\Src\Hello", "c:\Dest\" 'Copy all folders starting with "Names" title to destination folder fso.CopyFolder "c:\Src\Names*", "c:\Dest\" 'Copy all folders to destination folder fso.CopyFolder "c:\Src\*", "c:\Dest\"