VBA Code to Create Multiple Folders
Automate folder creation in Windows using Excel VBA with ease and efficiency.
Introduction
Managing files and folders can be tedious if done manually. Using VBA (Visual Basic for Applications), you can automate the creation of multiple folders in a single click. This not only saves time but also reduces human error.
VBA Code Example
Sub CreateMultipleFolders()
Dim folderPath As String
Dim i As Integer
Dim folderNames As Variant
' Folder path where folders will be created
folderPath = "C:\Example\"
' Array of folder names
folderNames = Array("Folder1", "Folder2", "Folder3", "Folder4")
' Loop through each folder name and create folder
For i = LBound(folderNames) To UBound(folderNames)
If Dir(folderPath & folderNames(i), vbDirectory) = "" Then
MkDir folderPath & folderNames(i)
End If
Next i
MsgBox "Folders created successfully!", vbInformation
End Sub
Benefits of Using This VBA Code
- ✅ **Saves Time:** Quickly create multiple folders without manual effort.
- ✅ **Reduces Errors:** No risk of spelling mistakes or creating wrong folder names.
- ✅ **Automation:** Can be linked to Excel sheets to dynamically create folders based on data.
- ✅ **Organized Workflow:** Perfect for projects, reports, or any system requiring structured folders.
Advantages
- 🔹 Easy to customize folder names and paths.
- 🔹 Works with arrays for batch folder creation.
- 🔹 Can be expanded to create subfolders automatically.
- 🔹 Integrates seamlessly with Excel, making it ideal for office automation.
How to Use
- Open Excel and press ALT + F11 to open the VBA editor.
- Insert a new module and paste the code above.
- Modify the
folderPathandfolderNamesarray as per your requirement. - Run the macro, and the folders will be created automatically.

0 Comments