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".
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.

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"
        MkDir xdir
        MsgBox "Folder created"
    End If

End Sub

Open in new window

error_proneAuthor Commented:
How do I change the msg "Folder Exists" to basically have it keep going?  Type in Resume Next?
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.
error_proneAuthor Commented:
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.