Lecture d'un fichier excel pour enregistrement dans une table
Bonjour à tous,
J'ai développé une application sous access 2003 pour une gestion de stock dans mon entreprise.
Un bouton me permet (normalement) d'aller choisir un fichier excel pour que ses données soient parcourues et insérées dans mes tables.
Cette application fonctionnait très bien sous access 2003 mais nous venons de passer à access 2016 et depuis plus rien.
La fenêtre qui me permettait de choisir le fichier à lire ne s'ouvre pas.
elle est appelée par la fonction ap_openFile()
Code:
1 2
| Dim nameFile As String
nameFile = ap_OpenFile() |
Le code de cette fonction (que j'avais du pomper sur le web) est le suivant:
Code:
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 |
Je ne comprends pas tout ce code mais cela fonctionnait avant et je n'ai plus la fenetre de dialogue. pourriez vous m'aider SVP ?