Folders

srizki

Well-known Member
Joined
Jan 14, 2003
Messages
1,857
Office Version
  1. 365
Platform
  1. Windows
It is not really an excel question, but it is relevent.
I want to create some over 200 folders name "Moveable Assets" under each of existing folders. I will have to to to each folder and create one.
Is there a way to create all folders at the same time? like highlight all the folders and go to file > New > Folder ??
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try this. Please heed the warnings
Code:
'=============================================================================
'- MAKE MULTIPLE NEW FOLDERS
'- Makes a new folder in each subfolder of the specified Base folder
'-----------------------------------------------------------------------------
'- THERE IS A OPTION TO ADD NEW FOLDERS TO SUBFOLDERS TOO
'- USE EXTREME CARE WITH THIS ONE.
'- IT WILL USE *EVERY* FOLDER AND SUBFOLDER IN THE BASE FOLDER
'- ......... except of the same name (eg. cannot make \TEST\TEST)
'-----------------------------------------------------------------------------
'- Brian Baulsom July 2010
'=============================================================================
'- SET VARIABLES
Const BaseFolder As String = "F:\test"      ' BASE FOLDER (no final backslash)
Const AddToSubFoldersToo As Boolean = False
Const NewFolderName As String = "TEST"      ' NAME FOR THE NEW FOLDER
'==============================================================================
'- FileSystemObject
Dim FSO As Object
Dim FolderName As String
Dim FolderSpec As String
Dim FolderCount As Long
'------------------------------------------------------------------------------
'=============================================================================
'-  MAIN ROUTINE
'=============================================================================
Sub MAKE_FOLDERS()
    rsp = MsgBox("Base Folder :  " & BaseFolder & vbCr _
        & "Add subfolders ?" & vbCr _
        & "New Folder :  " & NewFolderName, vbOKCancel)
    If rsp = vbCancel Then Exit Sub
    '-------------------------------------------------------------------------
    '- INITIALISE
    Set FSO = CreateObject("Scripting.FileSystemObject") ' FILE SYSTEM OBJECT
    Application.Calculation = xlCalculationManual
    FolderCount = 0
    '==========================================================================
    '- CALL FOLDER SUBROUTINE
    GetSubFolders (BaseFolder)
    '==========================================================================
    '- FINISH
    MsgBox ("Made " & FolderCount & " new folders.")
    Application.Calculation = xlCalculationAutomatic
    Application.StatusBar = False
End Sub
'========  END OF MAIN ROUTINE =================================================
'===============================================================================
'- SUBROUTINE 1 :  GET SUBFOLDERS
'- Called from Main routine and also calls itself
'===============================================================================
Private Sub GetSubFolders(FolderSpec)
    Dim F, f1, fc, s
    Set F = FSO.GetFolder(FolderSpec)
    Set fc = F.SubFolders
    '--------------------------------------------------------------------------
    '- CHECK SUBFOLDER COUNT
    If fc.Count = 0 Then
        'There are no sub folders in (FolderSpec)
        Exit Sub
    Else
        '- LOOP FOLDERS
        For Each f1 In fc
            FolderName = f1.path
            '==================================================================
            MAKE_NEW_FOLDER FolderName          ' CALL MkDir() SUBROUTINE
            '==================================================================
            '- CALL SELF TO GET SUBFOLDERS
            If AddToSubFoldersToo = True Then
                GetSubFolders (FolderName)      ' CALLS ITSELF
            End If
            '==================================================================
        Next
    End If
    '--------------------------------------------------------------------------
End Sub
'==============================================================================
'==============================================================================
'-SUBROUTINE 2 : CALLED FROM SUBROUTINE 1 : MAKE A NEW FOLDER
'==============================================================================
Private Sub MAKE_NEW_FOLDER(CurrentFolder)
    Dim NewFolder As String, n
    '-------------------------------------------------------------------------
    '- IGNORE NEW FOLDER ALREADY ADDED
    If Right(CurrentFolder, Len(NewFolderName)) = NewFolderName Then Exit Sub
    NewFolder = CurrentFolder & "\" & NewFolderName
    '-------------------------------------------------------------------------
    '- CODE FOR TESTING (comment out when working as required)
    rsp = MsgBox("Current Folder : " & CurrentFolder & vbCr _
            & "Make new '" & NewFolderName & "' folder ?", vbOKCancel)
    If rsp = Cancel Then Exit Sub
    '-------------------------------------------------------------------------
    '- MAKE THE FOLDER
    On Error Resume Next
    MkDir NewFolder
    If Err.Number <> 0 Then
        'There is already a folder (NewFolderName)
        Exit Sub
    Else
        FolderCount = FolderCount + 1
        Application.StatusBar = FolderCount & " : " & FolderName
    End If
    '-------------------------------------------------------------------------
End Sub
'==============================================================================
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top