?
Solved

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

Posted on 2013-11-22
3
Medium Priority
?
484 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 39668606
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
ID: 39668609
How many subfolders you want to create?

Will they remain constant or dynamic?
0
 

Author Closing Comment

by:Tocogroup
ID: 39668657
Many thanks for that. It worked a treat.
Toco
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

741 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