Allows user to choose a file
Shows the user a familiar ‘explorer’ type dialogue box
Allows the use of a ‘start’ folder
Allows the developer to define the use of file multiselect or not
Author: michael@excelexperts.co.uk
Function BrowseFile(Title As String, _
Optional InitialFolder As String, Optional sFileDesc As String, Optional sFileExt As String, _
Optional InitialView As Office.MsoFileDialogView = msoFileDialogViewList) As String
Dim v As Variant
Dim InitFolder As String
With Application.FileDialog(msoFileDialogFilePicker)
.Title = Title
.InitialView = InitialView
.AllowMultiSelect = False
If Len(InitialFolder) > 0 Then
If Dir(InitialFolder, vbDirectory) <> vbNullString Then
InitFolder = InitialFolder
If Right(InitFolder, 1) <> Application.PathSeparator Then
InitFolder = InitFolder & Application.PathSeparator
End If
.InitialFileName = InitFolder
End If
End If
.Filters.Clear
.Filters.Add sFileDesc, sFileExt
.Show
On Error Resume Next
Err.Clear
v = .SelectedItems(1)
If Err.Number <> 0 Then
v = vbNullString
End If
End With
BrowseFile = CStr(v)
End Function