Public Function SelectFolder() As String
'Requires Office XP (2002) or higher
'Requires a reference to the Microsoft Office Object Library
'Created by Helen Feddema 3-Aug-2009
'Last modified 3-Aug-2009
On Error GoTo ErrorHandler
Dim strFolderPath As String
Dim fd As Office.FileDialog
'Create a FileDialog object as a Folder Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.Title = "Browse for folder where Word templates are located"
.ButtonName = "Select"
.InitialView = msoFileDialogViewDetails
'.InitialFileName = strPath
If .Show = -1 Then
strFolderPath = CStr(fd.SelectedItems.Item(1)) & "\"
Else
Debug.Print "User pressed Cancel"
strFolderPath = ""
End If
End With
SelectFolder = strFolderPath
ErrorHandlerExit:
Exit Function
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
Resume ErrorHandlerExit
End Function
|