Select Folder - Complicated Task

Delta Star

Board Regular
Joined
Oct 28, 2009
Messages
184
I have a userform which allows me to create individual reports on mass.

This is accomplished via a userform which contains two combo boxes. The first is populated when opened (with counties) and once a selection is made the second box (towns) is populated.

The user then selects as many towns as they want and click a button which allows the user to decide which folder to place the reports in.

I need to ammend this so that once a folder is chose, a new folder is created automatically and named after the county that was selected from the first combobox and the reports saved to this newly created folder.

To complicate matters further, if the folder already exists then the reports should be added to it.

The code I'm using to select folder is shown below:-

HTML:
Option Explicit
Function PickFolder(strStartDir As Variant) As String
    Dim SA As Object, F As Object
    Set SA = CreateObject("Shell.application")
    Set F = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
    If (Not F Is Nothing) Then
        PickFolder = F.items.Item.Path
    End If
    Set F = Nothing
    Set SA = Nothing
End Function
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi

You can use the FileDialog to choose a folder (it's very easy to use) and can use Dir to determine if a folder exists, and if it doesn't MkDir to create one:

Code:
Dim strFolder As String, strNewFolder As String

With Application.FileDialog(msoFileDialogFolderPicker)
    .AllowMultiSelect = False
    .InitialFileName = "C:\"  'starting directory
    If .Show = -1 Then
        strFolder = .SelectedItems(1)
        strNewFolder = "County_Name_From_First_Combobox"
        If Len(Dir(strFolder & "\" & strNewFolder, vbDirectory)) = 0 Then _
            MkDir strFolder & "\" & strNewFolder 'folder doesn't yet exist! So create it
    Else
        'folder not selected
        Exit Sub
    End If
End With


'code to save all files to strFolder &"\" & strNewFolder
 
Upvote 0
I'm struggling to get the folder created. The combobox on the userform is called cmbCounty. I tried replacing "County_Name_From_First_Combobox" with "cmbCounty" but it just shows cmbCounty.

What am I doing wrong?
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,786
Members
452,942
Latest member
VijayNewtoExcel

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