Option Explicit
Sub TestGetFolder()
Dim sPath As String
' Use path for this workbook
' sPath = ThisWorkbook.Path
' Use descktop on Jim's computer.
sPath = "C:\Users\Jim\Desktop"
sPath = GetFolderFromUser(sPath)
Debug.Print "sPath = " & sPath
End Sub
Function GetFolderFromUser(Optional psStartPath As String = "") As String
Dim fldr As FileDialog
Dim sItem As String
Dim sPath As String
If psStartPath = "" _
Then
sPath = Application.DefaultFilePath
Else
sPath = psStartPath
End If
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = sPath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
GetFolderFromUser = sItem
Set fldr = Nothing
End Function