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

Posted on 2009-12-21
Last Modified: 2012-06-27
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".
Question by:error_prone
    LVL 59

    Accepted Solution

    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


    Author Comment

    How do I change the msg "Folder Exists" to basically have it keep going?  Type in Resume Next?
    LVL 59

    Expert Comment

    by:Saurabh Singh Teotia
    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.

    Author Closing Comment


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
    Introduction This Article is a follow-up to my Mappit! Addin Article (, it was inspired by an email posting I made to EUSPRIG (, I will briefly cover: 1) An overvie…
    Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
    The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now