Creating a folder

Posted on 2011-05-05
Last Modified: 2012-05-11
My application creates eight excel spreadsheet "reports".
I have automated naming them, and saving them.
They are saved to a destination folder.
The path is displayed to the user, who may change it if he or she wants to.
I can't assume user skill level. Like, preparing the folder first.
The destination folder may not exist.

What is the cleanest way to "ping" a path, and if the folder isn't there, to create it?
MkDir returns an error if the path exists, but I want to go the other direction.
Question by:NormaPosy
    LVL 76

    Accepted Solution

    You can use this function to test it.
    Function FolderExists(strFolder As String) As Boolean
        If Dir$(strFolder, vbDirectory) <> "" Then
            FolderExists = True
        End If
    End Function

    Open in new window

    LVL 76

    Expert Comment

    Are you using a dialogue to allow the user to browse for the folder (and file name)? If so it will be difficult to select a non-existent folder.

    Author Closing Comment

    Thank You.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    734 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

    24 Experts available now in Live!

    Get 1:1 Help Now