Cita: Hola Reel, si uso ese control tengo que hacer otra pantalla y estoy seguro que hay una funcion que levanta un Dialogo para seleccionar una Carpeta y devuelve el Path de la misma.
Exacto, si existe una funcion para hacer esto, aqui esta el Codigo:
Código:
Const MAX_PATH = 255
Private Enum eBIF
BIF_RETURNONLYFSDIRS = &H1 'Sólo directorios del sistema
BIF_DONTGOBELOWDOMAIN = &H2 'No incluir carpetas de red
BIF_STATUSTEXT = &H4
BIF_RETURNFSANCESTORS = &H8
BIF_BROWSEFORCOMPUTER = &H1000 'Buscar PCs
BIF_BROWSEFORPRINTER = &H2000 'Buscar impresoras
End Enum
Private Type BrowseInfo
hwndOwner As Long
pIDLRoot As Long 'Especifica dónde se empezará a mostrar
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
(lpbi As BrowseInfo) As Long
Private Declare Sub CoTaskMemFree Lib "ole32.dll" _
(ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32.dll" Alias "lstrcatA" _
(ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
(ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Function BrowseForFolder(ByVal hwndOwner As Long, ByVal sPrompt As String, Optional ByVal vFlags As eBIF) As String
'
Dim iNull As Integer
Dim lpIDList As Long
Dim lResult As Long
Dim sPath As String
Dim udtBI As BrowseInfo
Dim lFlags As Long
If Not IsMissing(vFlags) Then
lFlags = CInt(vFlags)
End If
With udtBI
.hwndOwner = hwndOwner
.lpszTitle = lstrcat(sPrompt, "")
.ulFlags = lFlags Or BIF_RETURNONLYFSDIRS
End With
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(MAX_PATH, 0)
lResult = SHGetPathFromIDList(lpIDList, sPath)
Call CoTaskMemFree(lpIDList)
iNull = InStr(sPath, vbNullChar)
If iNull Then
sPath = Left$(sPath, iNull - 1)
End If
Else
'Se ha pulsado en cancelar
sPath = ""
End If
BrowseForFolder = sPath
End Function
Ojo: que si pones esto en un modulo cambia Private por Public.
Y luego simplemente llamas la funcion desde un Boton o lo que sea que utilices:
Código:
Private Sub Command1_Click()
Dim carpeta As String
carpeta = BrowseForFolder(Me.hWnd, "Selecciona un directorio")
MsgBox carpeta
End Sub
Créditos a
el Guille
Saludos