To get to the folder you need, simply replace your existing .InitialFileName = ...line in CommandButton1_Click() with this:
.InitialFileName = "C:\Users\ra00036337\Desktop\My files" & "\" & Me.ComboBox1.Value & "\" & Me.ComboBox3.Value
As for the filename starting with A, B, or C... I presume you don't want user to select more than one, so it would be better to use grouped radio buttons for this (see attached workbook).
Private Sub CommandButton1_Click()
Dim sFolder As String
Dim initial As String
Dim initial_path As String
' loop through the radio buttons until we've found the one that's selected
For Each i In Me.Frame3.Controls
Debug.Print TypeName(i)
If TypeName(i) = "OptionButton" Then
If i.Value Then
initial = i.Caption
Exit For
End If
End If
Next i
' check for completion:
If Me.ComboBox1.Value = "" Then MsgBox "Please complete all inputs": Exit Sub
If Me.ComboBox3.Value = "" Then MsgBox "Please complete all inputs": Exit Sub
If initial = "" Then MsgBox "Please complete all inputs": Exit Sub
' now check initial path exists:
initial_path = "C:\Users\ra00036337\Desktop\My files" & "\" & Me.ComboBox1.Value & "\" & Me.ComboBox3.Value & "\"
If Dir(initial_path, vbDirectory) = "" Then MsgBox "Directory not found": Exit Sub
With Application.FileDialog(msoFileDialogFilePicker)
.Filters.Clear
.Filters.Add "Excel files", "*.xls*"
' excel won't accept a filter like "C*.xlsx", so include the initial in the filename instead:
.InitialFileName = initial_path & initial & "*"
If .Show = False Then Exit Sub
sFolder = .SelectedItems(1)
End With
End Sub
Your use of userform1 is obviously incomplete, so I've left it at that.
Does this help?
Tim
Bookmarks