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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
| Option Compare Database
Option Explicit
Public Enum Selection
Mono_Sélection = 1
Multi_Sélection = 2
End Enum
Public Enum acOpenFileType
allfiles
Image
MSAccess
MSExcel
MSOffice
MSWord
MultiMedia
Sound
End Enum
Public Const OFN_AllowMultiSelect = &H200
Public Const OFN_CreatePrompt = &H2000
Public Const OFN_EnableHook = &H20
Public Const OFN_EnableTemplate = &H40
Public Const OFN_EnableTemplateHandle = &H80
Public Const OFN_EXPLORER = &H80000
Public Const OFN_ExtensionDifferent = &H400
Public Const OFN_FileMustExist = &H1000
Public Const OFN_HideReadOnly = &H4
Public Const OFN_LongNames = &H200000
Public Const OFN_NoChangeDir = &H8
Public Const OFN_NoDeReferenceLinks = &H100000
Public Const OFN_NoLongNames = &H40000
Public Const OFN_NoNetWorkButton = &H20000
Public Const OFN_NoReadOnlyReturn = &H8000
Public Const OFN_NoTestFileCreate = &H10000
Public Const OFN_NoValiDate = &H100
Public Const OFN_OverWritePrompt = &H2
Public Const OFN_PathMustExist = &H800
Public Const OFN_ReadOnly = &H1
Public Const OFN_ShareAware = &H4000
Public Const OFN_ShareFallThrough = 2
Public Const OFN_ShareNoWarn = 1
Public Const OFN_ShareWarn = 0
Public Const OFN_ShowHelp = &H10
Public Dialogue As OpenFileName
Public strFiltre As String
Public strFile As String
Public strNomFile As String
Public RetVal As Long
Public tOpenFile As Variant
Public nOpenFile As Long
Public FileType As acOpenFileType
Public Type OpenFileName
lStructSize As Long
hwndOwner As Long
Instance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustomFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpInitialFolder As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" (pOpenfilename As OpenFileName) As Long
Public Declare Function GetSaveFileName Lib "comdlg32.dll" _
Alias "GetSaveFileNameA" (pOpenfilename As OpenFileName) As Long
Private Sub ExtendChoose(FileType As acOpenFileType)
Select Case FileType
Case allfiles
strFiltre = "Tous les fichiers" & Chr$(0) & "*.*"
Case Image
strFiltre = _
"Fichiers Jpg" & Chr$(0) & "*.jpg;*.jpeg" & Chr$(0) & _
"Fichiers Bmp" & Chr$(0) & "*.bmp" & Chr$(0) & _
"Fichiers Wmf" & Chr$(0) & "*.wmf" & Chr$(0) & _
"Fichiers Tif" & Chr$(0) & "*.tif" & Chr$(0) & _
"Tous les fichiers" & Chr$(0) & "*.*"
Case MSAccess
strFiltre = _
"Fichiers Access" & Chr$(0) & "*.mdb;*.mde;*.accdb;*.accde" & Chr$(0) & _
"Tous les fichiers" & Chr$(0) & "*.*"
Case MSExcel
strFiltre = _
"Fichiers Excel" & Chr$(0) & "*.xls;*.xlsx" & Chr$(0) & _
"Tous les fichiers" & Chr$(0) & "*.*"
Case MSOffice
strFiltre = _
"Fichiers Access" & Chr$(0) & "*.mdb;*.mde;*.accdb;*.accde" & Chr$(0) & _
"Fichiers Word" & Chr$(0) & "*.doc;*.docx;*.txt" & Chr$(0) & _
"Fichiers Excel" & Chr$(0) & "*.xls;*.xlsx" & Chr$(0) & _
"Tous les fichiers" & Chr$(0) & "*.*"
Case MSWord
strFiltre = _
"Fichiers Word" & Chr$(0) & "*.doc;*.docx;*.txt" & Chr$(0) & _
"Tous les fichiers" & Chr$(0) & "*.*"
Case MultiMedia
strFiltre = _
"Fichiers Mpg" & Chr$(0) & "*.mpg;*.mpeg" & Chr$(0) & _
"Fichiers Avi" & Chr$(0) & "*.avi" & Chr$(0) & _
"Fichiers Wmv" & Chr$(0) & "*.wmv" & Chr$(0) & _
"Fichiers Asx" & Chr$(0) & "*.asx" & Chr$(0) & _
"Tous les fichiers" & Chr$(0) & "*.*"
Case Sound
strFiltre = _
"Fichiers Mp3" & Chr$(0) & "*.mp3;*.mpc" & Chr$(0) & _
"Fichiers Wav" & Chr$(0) & "*.wav" & Chr$(0) & _
"Tous les fichiers" & Chr$(0) & "*.*"
End Select
End Sub
Private Sub openFileSort(Tableau As Variant, Optional SortAscending As Boolean = True)
Dim Changement As Boolean
Dim Indice As Long
Dim strTmp As Variant
Dim Début As Long
Dim Fin As Long
Début = LBound(Tableau) + 1
Fin = UBound(Tableau) - 2
Do
Changement = False
For Indice = Début To Fin
If (Tableau(Indice) > Tableau(Indice + 1) And SortAscending) _
Or (Tableau(Indice) < Tableau(Indice + 1) And Not SortAscending) Then
strTmp = Tableau(Indice)
Tableau(Indice) = Tableau(Indice + 1)
Tableau(Indice + 1) = strTmp
Changement = True
End If
Next Indice
Loop Until Not Changement
End Sub
Public Function OpenFile(Optional InitialFolder As String = "", _
Optional MultiSelect As Selection = Mono_Sélection, _
Optional ModalWindow As Boolean = True, _
Optional FileType As acOpenFileType = MSOffice, _
Optional KbBufferLength As Long = 4, _
Optional WithPath As Boolean = True, _
Optional FileName As String = "", _
Optional SortAsc As Boolean = True _
) As String
OpenFile = ""
If InitialFolder = "" Then InitialFolder = CurrentProject.Path
If KbBufferLength < 4 Or KbBufferLength > 63 Then
KbBufferLength = 4
End If
ExtendChoose FileType
With Dialogue
If ModalWindow Then
.hwndOwner = Access.hWndAccessApp
Else
.hwndOwner = 0
End If
.lStructSize = Len(Dialogue)
.lpstrFilter = strFiltre
.lpInitialFolder = InitialFolder
.lpstrTitle = "Recherche d'un fichier"
If MultiSelect = Mono_Sélection Then
.lpstrFile = FileName & (Space(254 - Len(FileName)))
.nMaxFile = 255
.lpstrFileTitle = Space(254)
.nMaxFileTitle = 255
.Flags = 6148
Else
.lpstrFile = FileName & Space((KbBufferLength * 4096) - 2 - Len(FileName))
.nMaxFile = ((KbBufferLength * 4096) - 1)
.lpstrFileTitle = Space((KbBufferLength * 4096) - 2)
.nMaxFileTitle = ((KbBufferLength * 4096) - 1)
.Flags = 6148 Or OFN_FileMustExist _
Or OFN_EXPLORER _
Or OFN_AllowMultiSelect
End If
End With
RetVal = GetOpenFileName(Dialogue)
If RetVal = 0 Then
OpenFile = ""
nOpenFile = 0
Exit Function
End If
OpenFile = Trim(Dialogue.lpstrFile)
OpenFile = Left(OpenFile, Len(OpenFile) - 1)
OpenFile = Replace(OpenFile, Chr(0), ";")
tOpenFile = Split(OpenFile, ";")
If UBound(tOpenFile) = 0 Then
nOpenFile = 1
ElseIf UBound(tOpenFile) = 1 Then
OpenFile = Replace(OpenFile, ";", "")
nOpenFile = 1
Else
nOpenFile = UBound(tOpenFile) - 1
openFileSort tOpenFile, SortAsc
OpenFile = Join(tOpenFile, ";")
End If
If Not WithPath Then
If InStr(1, OpenFile, ";") > 0 Then
OpenFile = Mid(OpenFile, InStr(1, OpenFile, ";") + 1)
Else
OpenFile = Mid(OpenFile, InStrRev(OpenFile, "\") + 1)
End If
End If
End Function
Public Function SaveFile(Optional InitialFolder As String = "", _
Optional FileType As acOpenFileType = allfiles, _
Optional FileName As String = "" _
) As String
SaveFile = ""
If InitialFolder = "" Then InitialFolder = CurrentProject.Path
ExtendChoose FileType
With Dialogue
.hwndOwner = Access.hWndAccessApp
.lStructSize = Len(Dialogue)
.lpstrFilter = strFiltre
.lpstrFile = FileName & (Space(254 - Len(FileName)))
.nMaxFile = 255
.lpstrFileTitle = Space(254)
.nMaxFileTitle = 255
.lpInitialFolder = InitialFolder
.lpstrTitle = "Sauvegarde d'un fichier"
.Flags = 6148
End With
RetVal = GetSaveFileName(Dialogue)
If RetVal >= 1 Then
SaveFile = Trim(Dialogue.lpstrFile)
SaveFile = Replace(SaveFile, Chr(0), "")
Else
SaveFile = ""
Exit Function
End If
End Function |
Partager