I like it so much, I've made a multi purpose version:
[vba]Public Function OpenFileDialog(DisplayText As String, FilterText As String, ParamArray Filter()) As Variant
'// Ref required:= Microsoft Office 11.0 Object Library
'// Returns an array of selected items
'// ToUSe:
'// ItemArray() = OpenFileDialog("Please Select...","Images","*.gif","*.jpg","*.png","*.bmp")
Dim fd As FileDialog
Dim vrtSelectedItem As Variant
Dim arySelectedItems() As String
Dim strFilters As String
Dim i As Integer
Set fd = Application.FileDialog(msoFileDialogFilePicker)
For i = LBound(Filter) To UBound(Filter)
strFilters = strFilters & IIf(i > LBound(Filter), ";", "") & Filter(i)
Next i
i = 0
With fd
.Title = DisplayText
.Filters.Add FilterText, strFilters, 1
.AllowMultiSelect = True
.InitialFileName = CurrentProject.path
'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the button.
If .Show = True Then
ReDim arySelectedItems(.SelectedItems.count)
'Step through each string in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems
arySelectedItems(i) = vrtSelectedItem
'Debug.Print arySelectedItems(i) ' <-- used for testing
i = i + 1
Next vrtSelectedItem
End If
End With
'Set the object variable to nothing.
Set fd = Nothing
OpenFileDialog = arySelectedItems
End Function[/vba]




Reply With Quote