Sélection de dossier

Parcourir et Sélectionner un dossier (API)

Retourne le nom du dossier sélectionné

'/
'/ A placer dans la partie déclarative
'/
Private Type BROWSEINFO
    hOwner As Long
    pidlRoot As Long
    pszDisplayName As String
    lpszTitle As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long
End Type

Private Declare Function SHBrowseForFolder _
                          Lib "shell32.dll" _
                              Alias "SHBrowseForFolderA" _
                              (lpBrowseInfo As BROWSEINFO) As Long

Private Const BIF_RETURNONLYFSDIRS = &H1

Private Declare Function SHGetPathFromIDList _
                          Lib "shell32.dll" _
                              Alias "SHGetPathFromIDListA" _
                              (ByVal pidl As Long, _
                               ByVal pszPath As String) As Long

La fonction :

Public Function GetFolderName(Optional szDialogTitle As Variant) As String
    If IsMissing(szDialogTitle) Then
        szDialogTitle = "Veuillez sélectionner le dossier"
    End If
    Dim x As Long
    Dim bInfo As BROWSEINFO
    Dim dwIList As Long
    Dim szPath As String
    Dim wPos As Integer
    With bInfo
        .hOwner = hWndAccessApp
        .lpszTitle = szDialogTitle
        .pidlRoot = 0&
        .ulFlags = BIF_RETURNONLYFSDIRS
    End With
    dwIList = SHBrowseForFolder(bInfo)
    szPath = Space$(512)
    x = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
    If x Then
        wPos = InStr(szPath, Chr(0))
        GetFolderName = Left$(szPath, wPos - 1)
    Else
        GetFolderName = ""
    End If
End Function

Dernière modification : 19/02/2010 19:27
Catégorie : Les mémos - Fichiers
Page lue 7106 fois