1. Folder
Dim objFD As Object Dim strOut As String strOut = vbNullString 'msoFileDialogFolderPicker = 4 Set objFD = Application.FileDialog(4) If objFD.Show = -1 Then strOut = objFD.SelectedItems(1) End If Set objFD = Nothing FolderSelection = strOut Dim strChoice As String strChoice = FolderSelection If Len(strChoice) > 0 Then Me.Text1 = strChoice Else ' what should happen if user cancelled selection? End If
2. File
Dim objDialog As Object Set objDialog = Application.FileDialog(3) With objDialog .AllowMultiSelect = False .Show If .SelectedItems.Count = 0 Then MsgBox "No file selected." Else 'Me.Text1 = Dir(.SelectedItems(1)) Me.Text1 = .SelectedItems(1) End If End With Set objDialog = Nothing