Aqui tienes el codigo de declaracion del BrowserDialog en el API de Windows y una funcion para llamarlo comodamente desde tu programa:
Module1.bas
Código:
Option Explicit
'Constantes para ventana de directorios:
Public Const BIF_BROWSEFORCOMPUTER = 1000
Public Const BIF_BROWSEFORPRINTER = 2000
Public Const BIF_DONTGOBELOWDOMAIN = 2
Public Const BIF_RETURNFSANCESTORS = 8
Public Const BIF_RETURNONLYFSDIRS = 1
Public Const BIF_STATUSTEXT = 4
Public Const MAX_SIZE = 255
'Estructura para ventana de directorios:
Public Type BROWSEINFO
hwndOwner 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
'Abre la ventana de seleccion de directorio:
Public Declare Function BrowseFolderDlg Lib "shell32.dll" Alias "SHBrowseForFolder" (lpBrowseInfo As BROWSEINFO) As Long
'Devuelve la ruta del directorio seleccionado en la ventana de seleccion de directorio:
Public Declare Function GetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDList" (ByVal PointerToIDList As Long, ByVal pszPath As String) As Long
'Abre la ventana de seleccion de directorio:
Public Function DLG_BrowseFolder(hwnd As Long, Title As String) As String
On Local Error Resume Next
Dim mBrowseInfo As BROWSEINFO
Dim mPointerToIDList As Long
Dim mResult As Long
Dim mPathBuffer As String
Dim sReturn As String
sReturn = ""
With mBrowseInfo
.hwndOwner = hwnd
.pidlRoot = 0
.lpszTitle = Title
.pszDisplayName = String(MAX_SIZE, Chr(0))
.ulFlags = BIF_RETURNONLYFSDIRS
End With
mPointerToIDList = BrowseFolderDlg(mBrowseInfo)
If mPointerToIDList <> 0& Then
mPathBuffer = String(MAX_SIZE, Chr(0))
mResult = GetPathFromIDList(ByVal mPointerToIDList, ByVal mPathBuffer)
sReturn = Left$(mPathBuffer, InStr(mPathBuffer, Chr(0)) - 1)
End If
DLG_BrowseFolder = sReturn
End Function
Luego para llamarlo tan sencillo como esto:
Código:
Option Explicit
Private Sub Form_Load()
MsgBox = DLG_BrowseFolder(Me.hwnd, "Seleccione directorio")
End Sub
Salu2...