Solved

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

Posted on 2013-11-22
3
436 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 50

Accepted Solution

by:
Rgonzo1971 earned 500 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

726 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