1ublic Function GetUserFolder(strCaption As String, _
2 Optional InitialFile As String, _
3 Optional bMultiSelect As Boolean = False) As String
4
5On Error GoTo eh
6
7Const PROC_NAME As String = "GetUserFolder"
8
9Dim FD As FileDialog
10
11'Create a FileDialog object as a File Picker dialog box.
12Set FD = Application.FileDialog(msoFileDialogFolderPicker)
13
14With FD
15 If Not Len(strCaption) = 0 Then
16 .Title = strCaption
17 End If
18 If Len(InitialFile) > 0 Then
19 .InitialFileName = InitialFile
20 End If
21 .AllowMultiSelect = bMultiSelect
22
23
24 'Use the Show method to display the File Picker dialog box and return the user's action.
25 'The user pressed the action button.
26 If .Show = -1 Then
27 GetUserFolder = .SelectedItems(1)
28 Else
29 End If
30End With
31
32exitProc:
33 Set FD = Nothing
34 Exit Function
35eh:
36 'will log the error and then raise an error back to client
37 Resume exitProc
38
39
40End Function