Solved

How do I create folders within a folder in Excel VBA ?

Posted on 2013-11-22
3
386 Views
Last Modified: 2013-11-22
Hi,

I have an Excel 2010 VBA application in which I create a new empty folder ("\Training") on my C: drive. This works successfully.

However, I want to also create 2 empty subfolders within the \Training folder but I'm not sure how to do this.

Further, how do I check MKDIR to ensure it has successfully created the folders ?

This is my code thus far ...

   Dim MyPath As String
       
   MyPath = Environ("USERPROFILE") & "\Training"

   If Len(Dir(MyPath, vbDirectory)) = 0 Then
      MkDir MyPath
      ' Create a '\Booking' folder  and a '\Finance' folder inside the '\Training' folder
      MsgBox "A new Windows folder with subfolders has been created successfully", vbInformation
   End If


Thanks for your help
Toco
0
Comment
Question by:Tocogroup
3 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
Hi,

Pls try

   Dim MyPath As String, MyPathB As String, MyPathF As String
       
   MyPath = Environ("USERPROFILE") & "\Training"

   If Len(Dir(MyPath, vbDirectory)) = 0 Then
      MkDir MyPath
      MyPathB = Environ("USERPROFILE") & "\Training\Booking"
      If Len(Dir(MyPathB, vbDirectory)) = 0 Then
        MkDir MyPathB
      End If
      MyPathF = Environ("USERPROFILE") & "\Training\Finance"
      If Len(Dir(MyPathF, vbDirectory)) = 0 Then
        MkDir MyPathF
      End If
      ' Create a '\Booking' folder  and a '\Finance' folder inside the '\Training' folder
      MsgBox "A new Windows folder with subfolders has been created successfully", vbInformation
   End If

Open in new window

Regards
0
 
LVL 6

Expert Comment

by:Ramakrishna Prabhu
Comment Utility
How many subfolders you want to create?

Will they remain constant or dynamic?
0
 

Author Closing Comment

by:Tocogroup
Comment Utility
Many thanks for that. It worked a treat.
Toco
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

771 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

10 Experts available now in Live!

Get 1:1 Help Now