Create A New Folder Using VBA and Excel Cell Reference for Folder Name

Is it possible to create a new folder where the path name is in an Excel cell?  Also, the folder name would be the current date in this format, "YYYYMMDD".
error_proneAsked:
Who is Participating?
 
Saurabh Singh TeotiaConnect With a Mentor Commented:
Assuming you have path in cell A1, then you can use the following code, Also to use the code you need to have microsoft scripting runtime library selected, To do that in vb editor go to tools-->references and search for the library and add it.
Saurabh...

Sub checkfolder()
    Dim xdir As String
    Dim objfile As Object

    xdir = Range("A1").Value & "\" & Format(Now(), "yyyymmdd")

    Set objfile = New FileSystemObject

    If objfile.FolderExists(xdir) Then

        MsgBox "Folder Exists"
    Else
        MkDir xdir
        MsgBox "Folder created"
    End If





End Sub

Open in new window

0
 
error_proneAuthor Commented:
How do I change the msg "Folder Exists" to basically have it keep going?  Type in Resume Next?
0
 
Saurabh Singh TeotiaCommented:
Enter your code after end if that is after line-16 and it will keep on going the code after the message and if you want to remove the message then change the line-11 that is completely remove it which will remove the message.
Saurabh...
0
 
error_proneAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.