+ Reply to Thread
Results 1 to 4 of 4

Quickly create folders and subfolders with vba

Hybrid View

amartin575 Quickly create folders and... 10-17-2019, 04:17 PM
karedog Re: Quickly create folders... 10-18-2019, 12:36 AM
amartin575 Re: Quickly create folders... 10-18-2019, 11:44 AM
karedog Re: Quickly create folders... 10-19-2019, 12:45 AM
  1. #1
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Quickly create folders and subfolders with vba

    Hello,

    I have the attached file and code used to create folders and subfolders on the fly. It usually performs the task rather quickly however I have a lot of folders and subs to create now and the file is taking a long time to complete. Any recommendations on altering the code below to make it run faster?

    Sub CreateFolderStructure()
        Dim objRow As Range, objCell As Range, strFolders As String
    
        For Each objRow In ActiveSheet.UsedRange.Rows
            strFolders = "C:\Users\Anthony.Martin\Documents\0-Test"
            For Each objCell In objRow.Cells
                strFolders = strFolders & "\" & objCell
            Next
            Shell ("cmd /c md " & Chr(34) & strFolders & Chr(34))
        Next
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Quickly create folders and subfolders with vba

    Maybe :
    Option Explicit
    #If Win64 Then
        Private Declare PtrSafe Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath As String) As Boolean
    #Else
        Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath As String) As Boolean
    #End If
    
    Sub CreateFolderStructure2()
        Dim objRow As Range, objCell As Range, strFolders As String
    
        For Each objRow In ActiveSheet.UsedRange.Rows
            strFolders = "C:\Users\Anthony.Martin\Documents\0-Test"
            For Each objCell In objRow.Cells
                strFolders = strFolders & "\" & objCell
            Next
            strFolders = strFolders & "\"
            MakeSureDirectoryPathExists strFolders
        Next
    End Sub
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Forum Contributor
    Join Date
    10-24-2012
    Location
    Chicago
    MS-Off Ver
    O365
    Posts
    311

    Re: Quickly create folders and subfolders with vba

    wow that was much much faster. Thanks.

  4. #4
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Quickly create folders and subfolders with vba

    You are welcome, thanks for marking the thread as solved and rep.points.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to create folders and subfolders
    By Sun13Banjo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2019, 07:26 AM
  2. Create folders in all the subfolders and move subfolders
    By Amarjeet Singh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2015, 12:51 PM
  3. [SOLVED] VBA code to add folders and subfolders
    By rhlittau in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-25-2013, 06:57 PM
  4. [SOLVED] Creating Folders and Subfolders
    By matt1133 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-15-2013, 03:52 AM
  5. Use VBA to create hyperlinks to every file in a directory or folders and subfolders
    By Billdick7788 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-26-2012, 01:51 PM
  6. Listing folders and subfolders
    By brokenbiscuits in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-11-2011, 08:49 AM
  7. Traversing folders and subfolders
    By Michael in forum Excel General
    Replies: 2
    Last Post: 11-02-2005, 06:17 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1