Table of Contents
VBA (Visual Basic for Applications) is a programming language commonly used to automate tasks in Microsoft Office applications. With VBA, it is possible to create folders within a designated directory or folder. This can be achieved by using the “MkDir” function, which allows the user to specify the name and location of the new folder. Additionally, VBA can be used to create a loop to automate the process of creating multiple folders with different names. By utilizing VBA in this manner, users can save time and streamline the process of organizing and managing their files and folders.
Create Folders Using VBA (With Example)
You can use the MkDir statement to create a folder using VBA.
Here is one common way to use this statement in practice:
Sub CreateFolder()
MkDir "C:UsersBobDesktopMy_Data"
End Sub
This particular macro will create a folder called My_Data on the Desktop of my computer.
The following example shows how to use this function in practice.
Example: Create a Folder Using VBA
Suppose my Desktop currently has two folders in it:

Suppose I would like to use VBA to create a folder called My_Data on the Desktop.
I can create the following macro to do so:
Sub CreateFolder()
MkDir "C:UsersBobDesktopMy_Data"
End SubOnce I run this macro and open the File Explorer to navigate to the Desktop, I can see that this new folder has been created:

I can see that the new folder called My_Data has been created in the exact location that I specified.
Note that if this folder already existed in this location and I ran this macro, I would receive the following error:

The error box tells us that there is a Path/File access error because a folder with this name already exists in this location on my computer.
Cite this article
stats writer (2024). How can I use VBA to create folders?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-create-folders/
stats writer. "How can I use VBA to create folders?." PSYCHOLOGICAL SCALES, 24 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-create-folders/.
stats writer. "How can I use VBA to create folders?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-create-folders/.
stats writer (2024) 'How can I use VBA to create folders?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-use-vba-to-create-folders/.
[1] stats writer, "How can I use VBA to create folders?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I use VBA to create folders?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
