Compléments pour Microsoft Access

http://access.fr.free.fr/

Sélectionner fichier (Fichier)

Description 

Ce code permet d'ouvrir une boîte de dialogue afin de sélectionner un fichier.

Vous devez copier tout le code qui suit dans un module que vous pouvez appeler "modApiOpenFile".

 
Synthaxe 

Expression = OpenFile(strInitialDir)

La synthaxe de la fonction OpenFile comprend l'élément suivant :

ElémentsDescription

strInitialDir

Expression  de chaîne correspondant au répertoire par défaut de la fenêtre de sélection de fichier.
 
Exemple 

Aucun exemple disponible pour le moment.

 
Code de la fonction 


'***************************Debut du code***************************

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
lpstrInitialDir 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 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

Global Dialogue As OpenFileName

Public strFiltre As String
Public strFile As String
Public strNomFile As String
Public RetVal As Long

Public Function OpenFile(strInitialDir As String) As String

OpenFile = ""
strFiltre = "Fichiers Word" & Chr$­(0) & "*.doc;*txt" & Chr$­(0) & _
    "Fichiers Access" & Chr$­(0) & "*.mdb" & Chr$­(0) & _
    "Fichiers Excel" & Chr$­(0) & "*.xls" & Chr$­(0) & _
    "Tous les fichiers" & Chr$­(0) & "*.*"

With Dialogue
    .lStructSize = Len(Dialogue)
    .lpstrFilter = strFiltre
    .lpstrFile = Space(254)
    .nMaxFile = 255
    .lpstrFileTitle = Space(254)
    .nMaxFileTitle = 255
    .lpstrInitialDir = strInitialDir
    .lpstrTitle = "Recherche d'un fichier"
    .Flags = 6148 Or OFN_AllowMultiSelect Or OFN_LongNames Or OFN_EXPLORER
End With

RetVal = GetOpenFileName(Dialogue)

If RetVal >= 1 Then
    OpenFile = Dialogue.lpstrFile
Else
    OpenFile = ""
    Exit Function
End If

End Function

'***************************Fin du code***************************