


Now there are two ways you can start using FileSystemObject in Excel VBA: Since we are dealing with files and folders that are outside of the Excel application, we need to first create a reference to the library that holds these objects (drives, files, folders). Enabling FileSystemObject in Excel VBAįileSystemObject is not available by default in the Excel VBA. Just for the reference purpose, I have covered all the FileSystemObject methods (for each object) at the end of this tutorial. You will get a much better understanding when you go through the examples that I have covered in this tutorial. Similarly, if you want to copy a file, you will use the CopyFile method of the File object.ĭon’t worry if this seems overwhelming or hard to understand. To give you an example, if you want to delete a folder, you will use the DeleteFolder method of the Folder object. TextStream object allows you to create or read text files.Įach of the above objects has methods that you can use to work with these. For example, you can create, open, copy, move, and delete files using this object. For example, you can create, delete, rename, copy folders using this object.įile Object allows you to work with files in your system. What All Objects Can You Access Through FileSystemObject?Īs I mentioned above, you can access and modify files and folders using the FileSystemObject in VBA.īelow is a table that shows the most important objects that you can access and modify using FSO: Objectĭrive Object allows you to get information about the drive such as whether it exists or not, it’s path name, drive type (removable or fixed), it’s size, etc.įolder object allows you to create or modify folders in your system.

Note: FSO can only be used in Excel 2000 and later versions. FileSystemObject makes it easy to work with files and folders while keeping the code clean and short. While some of the things mentioned above can also be done using traditional VBA functions (such as the DIR function) and methods, that would lead to longer and more complicated codes. I will cover all these above examples (plus more) later in this tutorial. Get a list of all the file names (or sub-folder names) in a folder.Using it, you can access and modify the files/folders/directories in your computer system.įor example, below are some of the things you can do by using FileSystemObject in Excel VBA: Example 6: Copy All Files From One Folder to AnotherįileSystemObject (FSO) allows you to access the file system of your computer.Example 5: Copy a File from One Place to Another.Example 4: Get the List of All Sub-folders in a Folder.Example 3: Get a List of All Files in a Folder.Example 2: Create a New Folder in the Specified Location.Example 1: Check if a File or Folder Exists.Setting the Reference to the Microsoft Scripting Runtime Library.

