1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| Public Enum vaFileDialogFilterType
AllFile
ExcelFile
HtmlFile
ImagesFile
PdfFile
End Enum
'@Description "Ouvrir le sélecteur de dossiers."
Public Function GetFileOrFolderName( _
Optional ByVal InitialPath As String = vbNullString, _
Optional ByVal FileDialogType As Office.MsoFileDialogType = msoFileDialogFolderPicker, _
Optional ByVal FilterType As vaFileDialogFilterType = AllFile, _
Optional ByVal AllowMultiSelect As Boolean = False _
) As Variant
On Error GoTo catch
Dim localFileDialog As Office.FileDialog
Set localFileDialog = Application.FileDialog(FileDialogType)
With localFileDialog
.Filters.Clear
If FileDialogType = msoFileDialogFolderPicker Then
.Title = "Sélectionnez un dossier..."
Else
.Title = "Sélectionnez le" & _
IIf(AllowMultiSelect, "(s)", vbNullString) & _
"fichier" & IIf(AllowMultiSelect, "(s)", vbNullString) & " de destination."
.AllowMultiSelect = AllowMultiSelect
Select Case FilterType
Case AllFile
.Filters.Add "Tous les fichiers", "*.*", 1
Case ExcelFile
.Filters.Add "Documents Excel", "*.xls; *.xlsx; *.xlsm; *.xlst; *.xlsb; *.csv", 1
Case ImagesFile
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg; *.png; *.bmp", 1
Case HtmlFile
.Filters.Add "Documents Htm", "*.Htm; *.Html", 1
Case PdfFile
.Filters.Add "Fichiers Adobe PDF", "*.pdf; *.pdx; *.bpdx; *.fcdt; *.fdf", 1
End Select
End If
.InitialView = msoFileDialogViewList
If InitialPath = vbNullString Then
.InitialFileName = ThisWorkbook.Path
Else
.InitialFileName = IIf(Right$(.InitialFileName, 1) <> "\", "\", vbNullString)
End If
If .Show Then
If AllowMultiSelect = False Then
GetFileOrFolderName = .SelectedItems(1)
Else
Dim TempTab() As String
ReDim TempTab(1 To .SelectedItems.Count)
Dim Counter As Long
For Counter = 1 To .SelectedItems.Count
TempTab(Counter) = .SelectedItems(Counter)
Next Counter
GetFileOrFolderName = TempTab
End If
Else
GetFileOrFolderName = False
End If
End With
catch:
If Err.Number <> 0 Then
MsgBox "Erreur " & Err.Number & " (" & Err.Description & ")" & vbCrLf & _
"Dans la procédure 'GetFileOrFolderName'"
GetFileOrFolderName = False
End If
If Not localFileDialog Is Nothing Then Set localFileDialog = Nothing
End Function |
Partager