VBA Create Folder in Excel. We use MkDir VBA function to create a folder. We creates a folder in a specific directory or current directory. Once we create folder, we store file or files in it. If folder already exists then it throws an error message. In this tutorial we explained examples and step by step instructions.
VBA Create a Folder Example
Let us see an example how to create folder using VBA. In the below example we are trying to create a folder named ‘Files and Folders’. The created folder is empty.Now we can store files in it. You can change root folder path in the below example as per your requirement.
'VBA Creating Folder Sub VBAF1_Create_Folder() 'Variable declaration Dim sFolderPath As String 'Define root folder path to create folder sFolderPath = "C:\VBAF1\Files and Folders\" 'Create Folder MkDir sFolderPath 'Diplay messafe on the screen MsgBox "Folder has created : " & vbCrLf & vbCrLf & sFolderPath, vbInformation, "VBAF1" End Sub
Output: You can notice ‘Files and Folders’ new folder at ‘C:\VBAF1\’. You can create same folder in another root folder. But you can not create multiple times in the same folder. Please find the below screen shot for your reference.
Once we run above macro, it creates a folder. If we run again this macro, it throws ‘Path/File access error’ message on the screen. You can find below screenshot below for your reference.
Instructions to Run VBA Macro Code or Procedure:
You can refer the following link for the step by step instructions.
Instructions to run VBA Macro Code
Other Useful Resources:
Click on the following links of the useful resources. These helps to learn and gain more knowledge.
VBA Tutorial VBA Functions List VBA Arrays VBA Text Files VBA Tables
VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers Blog