Reputation: 105
I'm using macro to merge CSV files into one. Macro is working good, but I have one block, that allows to select a folder with CSV files to merge.
Two questions:
Code block:
'Browse to the folder with CSV files
Set oApp = CreateObject("Shell.Application")
Set oFolder = oApp.BrowseForFolder(0, "Select folder with CSV files", 512)
If Not oFolder Is Nothing Then
foldername = oFolder.Self.Path
If Right(foldername, 1) <> "\" Then
foldername = foldername & "\"
End If
now my availability to choose one folder from:
I would love to choose from more like this:
Upvotes: 2
Views: 6964
Reputation: 57683
Selecting multiple folders is not possible at all. Even selecting two folders at the same time will not work.
You can select …
Here is how to select one folder:
Public Sub SelectFolder()
Dim fdl As FileDialog
Set fdl = Application.FileDialog(msoFileDialogFolderPicker)
With fdl
.InitialFileName = "C:\Temp" 'where we start choosing a folder
If .Show <> -1 Then
MsgBox "canceled" 'nothing was selected
Else
Debug.Print .SelectedItems(1) 'the selected folder
End If
End With
End Sub
Upvotes: 3
Reputation: 29171
You can use Application.FileDialog
. This allows to browse the folder and select files.
Dim fileCount As Long
' Open the file dialog
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = True
.Filters.Clear
.Filters.Add "CSV files", "*.csv"
.Show
For fileCount = 1 To .SelectedItems.Count
Debug.print .SelectedItems(fileCount)
Next fileCount
End With
Upvotes: 3