You can use FileSystemObject.CreateFolder to create folder in excel vba. To use FileSystemObject object, you must add reference of Microsoft Scripting Runtime Library.
To create a reference of Microsoft Scripting Runtime Library follow the below steps:
First of all open the VBA editor by pressing “Alt + F11” -> navigate to “Tools” -> “Reference”
This will open a references window. Here select and check the entry “Microsoft Scripting Runtime” and click “OK”.
Now the reference to Microsoft Scripting Runtime Library has been added.
Nội dung chính
Example
Following example create a folder by using FileSystemObject.CreateFolder.
Sub createFolderOutput(path As String, folderName As String) Dim outputPath As String Dim objFso As FileSystemObject Set objFso = New FileSystemObject outputPath = objFso.BuildPath(path, folderName) If objFso.FolderExists(outputPath) = False Then objFso.CreateFolder outputPath End If Set objFso = Nothing End Sub