Consulting

Results 1 to 3 of 3

Thread: Windows Explorer on form

  1. #1

    Question Windows Explorer on form

    Hello Xperts,
    I need to figure out how to show a standard MS Windows explorer on a form, say in a TextBox, so that a user could select files used in the program.

    Thanks a lot!
    Serge.

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi Serge,
    Not sure if this is what your looking for but it opens a browse for folders dialog in excel.....
    [VBA]
    Option Compare Text
    Option Explicit

    Private Const BIF_RETURNONLYFSDIRS As Long = &H1
    Private Const BIF_DONTGOBELOWDOMAIN As Long = &H2
    Private Const BIF_RETURNFSANCESTORS As Long = &H8
    Private Const BIF_BROWSEFORCOMPUTER As Long = &H1000
    Private Const BIF_BROWSEFORPRINTER As Long = &H2000
    Private Const BIF_BROWSEINCLUDEFILES As Long = &H4000
    Private Const MAX_PATH As Long = 260

    Type BrowseInfo
    hOwner As Long
    pidlRoot As Long
    pszDisplayName As String
    lpszINSTRUCTIONS As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long
    End Type

    Type SHFILEOPSTRUCT
    hwnd As Long
    wFunc As Long
    pFrom As String
    pTo As String
    fFlags As Integer
    fAnyOperationsAborted As Boolean
    hNameMappings As Long
    lpszProgressTitle As String
    End Type

    Declare Function SHGetPathFromIDListA Lib "shell32.dll" ( _
    ByVal pidl As Long, _
    ByVal pszBuffer As String) As Long
    Declare Function SHBrowseForFolderA Lib "shell32.dll" ( _
    lpBrowseInfo As BrowseInfo) As Long

    Function BrowseFolder(Optional Caption As String = "") As String

    Dim BrowseInfo As BrowseInfo
    Dim FolderName As String
    Dim ID As Long
    Dim Res As Long

    With BrowseInfo
    .hOwner = 0
    .pidlRoot = 0
    .pszDisplayName = String$(MAX_PATH, vbNullChar)
    .lpszINSTRUCTIONS = Caption
    .ulFlags = BIF_RETURNONLYFSDIRS
    .lpfn = 0
    End With
    FolderName = String$(MAX_PATH, vbNullChar)
    ID = SHBrowseForFolderA(BrowseInfo)
    If ID Then
    Res = SHGetPathFromIDListA(ID, FolderName)
    If Res Then
    BrowseFolder = Left$(FolderName, InStr(FolderName, _
    vbNullChar) - 1)
    End If
    End If

    End Function
    Sub Macro1()
    Dim Path As String
    Dim Prompt As String
    Dim Title As String
    Path = BrowseFolder("Select A Folder")
    If Path = "" Then
    Prompt = "You didn't select a folder. The procedure has been canceled."
    Title = "Procedure Canceled"
    MsgBox Prompt, vbCritical, Title
    Else
    Prompt = "You selected the following path:" & vbNewLine & Path
    Title = "Procedure Completed"
    MsgBox Prompt, vbInformation, Title
    End If
    End Sub
    [/VBA]

    copy it all to a standard module and run macro1
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Hi Steve,
    I 've an it, looks OK. Only for my program I need to be able to point to a file whereas this code allows to select a folder only. Plus I would like to embed the resulting explorer into a form so it looks like a drop-down combo-box-like list, you know the standard style for all installing and wizard procedures.

    Thanks,
    Serge

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •