Solved

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

Posted on 2013-11-22
3
466 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 51

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

717 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