Return to VBA Code Examples

Move Files with VBA FileSystemObject (MoveFile)

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

Move Files with VBA FileSystemObject

The MoveFile method moves one or more files from one location to another.

Set VBA Reference

First, when using FileSystemObjects, you may have to set a reference to the VB script run-time library: open the Visual Basic Editor (ALT+F11), select Tools > References from the drop-down menu and tick the check-box of ‘Microsoft Scripting Runtime’.

vba references window


Second, you must create the FileSystemObject:

Now you have access to MoveFile, and the other FileSystemObject Methods.

Move One File

To move a single file, you can use the simple syntax of FSO.MoveFile( source, destination ).

As mentioned above, first you need to create the FileSystemObject:

Move Multiple Files

You can move multiple files with same name parts:

Or you can move multiple files with the same extension:

Or simply all files from a folder:

Notice, here we make use of the * wildcard character.

Instead of using the * wildcard, you can move all files in a folder using a For Each loop.

Move File to a New Folder

You can move the file(s) into a newly created folder as well. To do so, add the command

before declaring the destination path.

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! automacro

Learn More!!

Move Folders

You can use the analogue method MoveFolder for moving folders.