# Create folder with VBA



## mmn1000 (Jan 3, 2023)

Hello؛
    dear professors and friends, I have a question, please help me
    I want to have a folder called data in drive D, if it doesn't exist, it will ask with a message "Do you want to create the folder?" 
    If you answer "yes", the data folder will be created.


----------



## DanteAmor (Jan 3, 2023)

Try this:


```
Sub CreateFolder()
  Dim sFolder As String
  Dim resp As VbMsgBoxResult
  
  sFolder = "D:\data"
  If Dir(sFolder, vbDirectory) = "" Then
    resp = MsgBox("Do you want to create the folder", vbYesNo + vbQuestion)
    If resp = vbYes Then
      MkDir sFolder
    End If
  End If
End Sub
```


----------



## mmn1000 (Jan 3, 2023)

DanteAmor said:


> Try this:
> 
> 
> ```
> ...


*Thank you for your beautiful answer*


----------

