Palabras clave:
seleccionar, carpeta, directorio, GetFolderAutor:
Chea proporcionando un código de Terry Kreft
PreguntaQuisiera poder abrir una ventana desde un formulario que me mostrase el arbol de unidades con sus directorios y archivos y poder seleccionar uno de ellos desde una aplicación Access.
Responde CheaCopia el siguiente código en un módulo. Luego, para buscar un directorio basta con llamar a la función GetFolder()
'Code courtesy of
'Terry Kreft
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 SHGetPathFromIDList Lib "shell32.dll" Alias _
"SHGetPathFromIDListA" (ByVal pidl As Long, _
ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
"SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
As Long
Private Const BIF_RETURNONLYFSDIRS = &H1
'
Public Function GetFolder(szDialogTitle As String) As String
Dim X As Long, bi As BROWSEINFO, dwIList As Long
Dim szPath As String, wPos As Integer
With bi
' Im original:
.hOwner = hWndAccessApp
' Geändert zu:
'.hOwner = XHwnd
.lpszTitle = szDialogTitle
.ulFlags = BIF_RETURNONLYFSDIRS
End With
dwIList = SHBrowseForFolder(bi)
szPath = Space$(512)
X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
If X Then
wPos = InStr(szPath, Chr(0))
GetFolder = Left$(szPath, wPos - 1)
Else
GetFolder = ""
End If
End Function
Nombre archivo Búho: arboldirectorios.txt