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
|
Public Function ap_OpenFile(Optional ByVal strFileNameIn _
As String = "", Optional strDialogTitle _
As String = "Choisir un fichier")
Dim lngReturn As Long
Dim intLocNull As Integer
Dim strTemp As String
Dim ofnFileInfo As OpenFilename
Dim strInitialDir As String
Dim strFileName As String
'-- if a file path passed in with the name, '-- parse it and split it off.
If InStr(strFileNameIn, "\") <> 0 Then
strInitialDir = Left(strFileNameIn, InStrRev(strFileNameIn, "\"))
strFileName = Left(Mid$(strFileNameIn, _
InStrRev(strFileNameIn, "\") + 1) & _
String(256, 0), 256)
Else
strInitialDir = Left(CurrentDb.Name, _
InStrRev(CurrentDb.Name, "\") - 1)
strFileName = Left(strFileNameIn & String(256, 0), 256)
End If
With ofnFileInfo
.lStructSize = Len(ofnFileInfo)
.lpstrFile = strFileName
.lpstrFileTitle = String(256, 0)
.lpstrInitialDir = strInitialDir
.hwndOwner = Application.hWndAccessApp
.lpstrFilter = "EXCEL (*.xls)" & Chr(0) & "*.xls" & Chr(0)
.nFilterIndex = 1
.nMaxFile = Len(strFileName)
.nMaxFileTitle = ofnFileInfo.nMaxFile
.lpstrTitle = strDialogTitle
.Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly Or _
cdlOFNNoChangeDir
.hInstance = 0
.lpstrCustomFilter = String(255, 0)
.nMaxCustFilter = 255
.lpfnHook = 0
End With
lngReturn = ap_GetOpenFileName(ofnFileInfo)
If lngReturn = 0 Then
strTemp = ""
Else
'-- Trim off any null string
strTemp = Trim(ofnFileInfo.lpstrFile)
intLocNull = InStr(strTemp, Chr(0))
If intLocNull Then
strTemp = Left(strTemp, intLocNull - 1)
End If
End If
ap_OpenFile = strTemp
End Function |
Partager