How to create a folder in an specific directory with the name on specific cell?

SSF1590

Board Regular
Joined
Oct 20, 2019
Messages
73
Hello,

I am trying to create a code that allows me to create a folder in an specific directory with folder name on textbox1 and if this folder is already created in that directory, it does not allow to create another with the same name. As I am very new to Excel VBA, can you please help me with this code? I do not have any so far, nor I can think on any.

Thank you very much.
 
Last edited:

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi, thank you very much for your contribution.

I am not able to find the code that I need.

So far, I found the below, but it is not creating the folder at all, it does not show me error, it just does not create the folder. Can you please help me?

Dim NewFolder As String
Dim path As String


NewFolder = TextBox1.Text
path = "C:\Users\Anahi\Desktop\PCAR Project\Folders" & NewFolder


With CreateObject("Scripting.FileSystemObject")
If Not .FolderExists(path) Then .CreateFolder path
End With
 
Upvote 0
Does not look like you followed the instructions in the links.
 
Upvote 0
Try adding a \ as shown
Code:
path = "C:\Users\Anahi\Desktop\PCAR Project\Folders[COLOR=#ff0000]\[/COLOR]" & NewFolder
 
Upvote 0
I have added \ and it still does not create the folder and gives me the failure message as if the folder already exists.
 
Upvote 0
It shows me the MsgBox in my code "Folder creation failure"

Dim fso As Scripting.FileSystemObject
Dim newFolder As String
Dim path As String


newFolder = TextBox1.Text


path = "C:\Users\SSF1590\Desktop\Tara Project\Folders" & newFolder


Set fso = New Scripting.FileSystemObject


If Not fso.FolderExists(path) Then
fso.CreateFolder (path)


MsgBox ("Folder Created Sucessfully")
Else
MsgBox ("Folder Creation failure")
End If
 
Upvote 0
That code does not have the final \ in it.
Also are you sure that the folder doesn't already exist?
 
Upvote 0
I have corrected it and added \ but still no folder created. Yes, I am sure the folder does not exist. I have looked everywhere and the folder does not exist.
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,037
Members
449,062
Latest member
mike575

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top