Link to home
Start Free TrialLog in
Avatar of mAmitai
mAmitaiFlag for Israel

asked on

Selecting a folder using dialog

Hi
 
If I use the MS Common Cialog ocx in order to select a folder I can only select files.
How can i select a folder?

  Amitai
ASKER CERTIFIED SOLUTION
Avatar of samopal
samopal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this

Option Explicit
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 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

Private Sub Command1_Click()
    Dim Info As BROWSEINFO
    Dim PID As Long, Path As String, Tmp As String
    Dim localpath As String
     
    Info.HwndOwner = Me.hWnd
    Info.PidlRoot = &H0
    Info.LpszTitle = "Select File Path:"
    Info.UlFlags = &H1
    PID = SHBrowseForFolder(Info)
    Path = Space$(512)
    If (SHGetPathFromIDList(PID, Path)) Then localpath = Left$(Path, InStr(Path, Chr$(0)) - 1)
End Sub

If cancel is pressed, localpath is ""