Select Multiple Folders

Becquerel235

New Member
Joined
Jun 12, 2008
Messages
7
I'd like to open up a window to choose multiple folders and output them in an array of some sort. I've found how to do this for files, but can't see anything relating to multiple folders.

Currently I found this:

Code:
Function GetFolderName(Optional OpenAt As String) As String
    Dim lCount As Long
     
    GetFolderName = vbNullString
     
    With Application.FileDialog(msoFileDialogFolderPicker)
        .InitialFileName = OpenAt
        .Show
        For lCount = 1 To .SelectedItems.Count
            GetFolderName = .SelectedItems(lCount)
        Next lCount
    End With
End Function

to pick a folder. And i also wrote a little userform that does something similar, but it's pretty ugly.

Any ideas on how to select multiple folders in one dialog.

Thanks.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this in conjunction with your function:
Code:
Sub GetMultipleFolders()

    Dim sFolder As String
    Dim aFolders() As Variant
    Dim iFolderCount As Integer
    
    iFolderCount = 0
    sFolder = GetFolderName
    Do While sFolder <> ""
        ReDim Preserve aFolders(1 To iFolderCount + 1)
        aFolders(iFolderCount + 1) = sFolder
        iFolderCount = iFolderCount + 1
        sFolder = GetFolderName
    Loop
    
    MsgBox "The aFolders array holds the " & iFolderCount & " directories you selected."
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,800
Messages
6,126,980
Members
449,351
Latest member
Sylvine

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