Function BestandOpzoeken(Optional Pad As String) As String
Dim dlgPicker As FileDialog
Dim sType() As String, sFile As String
Dim tmp As String, sPad As String
Dim bCheck As Boolean
Dim vrtSelectedItem As Variant
On Error GoTo Hell
If Pad = "" Then sPad = CreateObject("WScript.Shell").SpecialFolders("MyDocuments") Else: sPad = Pad
If Right(sPad, 1) <> "\" Then sPad = sPad & "\"
Set dlgPicker = Application.FileDialog(msoFileDialogFilePicker)
With dlgPicker
.Title = "Selecteer een bestand." 'De titel voor het venster
.InitialFileName = sPad 'Waar moet het venster beginnen?
With .Filters
.Clear
.Add "Alles", "*.*", 1 'Geen Beperkingen op bestandstype"
.Add "Microsoft Word", "*.doc; *.docx; *.docm", 2 'Beperk de bestandstypes tot Word
.Add "Microsoft Excel", "*.xls; *.xlsx; *.xlsm", 3 'Beperk de bestandstypes tot Excel
.Add "Adobe Reader", "*.pdf", 4 'Beperk de bestandstypes tot .pdf"
.Add "Afbeeldingen", "*.jpg; *.jpeg; *.png", 5 'Beperk de bestandstypes tot afbeeldingen
End With
.FilterIndex = 1
.AllowMultiSelect = False 'Slechts één bestand kiezen toegestaan
.InitialView = msoFileDialogViewList 'Bepaal weergave
If .Show = -1 Then 'Bepaal of gebruiker op OK-knop heeft geklikt.
sFile = .SelectedItems(1) 'String wordt gevuld met geselecteerde bestand
Else
MsgBox "Er is op <Annuleren> gedrukt..."
BestandOpzoeken = "Annuleren"
GoTo Hell
End If
End With
BestandOpzoeken = sFile
Hell:
Set dlgPicker = Nothing
End Function