VBA MoveFile

The FileSystemObject VBA MoveFile function moves one or multiple files from current folder to another destination location.

VBA MoveFile Syntax

fso.MoveFile( source, destination )

source
Current location of one or multiple files. You can use wildcards such as *.* to specify more than a single file matching the pattern, however, only matching part of the last component of the file path.
destination
The destination location to which one or multiple files are to be moved.

Wildcards and Comments

You can use wildcards with the MoveFile functions:

  • * – replaces zero or more characters
  • ? – replaces one or more characters.

VBA Moving single files

Below example of how you can declare and define the FileSystemObject and move a single file between folders.

Set fso = CreateObject("Scripting.FileSystemObject")

'Move OldFolderName to C:\Dst and rename to NewFolderName
fso.MoveFile "C:\OlderFolderName\Hello.txt", C:\Dst\NewFolderName\NewFileName.txt"

VBA Moving multiple files

By using wildcards * and ? you can move multiple files between folders:

'Move all files matching wildcard to C:\Dst. This will keep their names
fso.MoveFile "C:\Src\Hello*.txt", C:\Dst\"

Alternatives in Windows

In Windows you can also move files by using: