Results 1 to 3 of 3

Thread: Dir Dialog

  1. #1
    Gold Lounger
    Join Date
    Dec 2000
    Hollywood (sorta), California, USA
    Thanked 0 Times in 0 Posts

    Dir Dialog

    What's a simple way to display a folder dialog so the user can select a folder but not a file?
    Kevin <IMG SRC= alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. #2
    5 Star Lounger
    Join Date
    Dec 2000
    Reading/Swindon, Berkshire, United Kingdom
    Thanked 0 Times in 0 Posts

    Re: Dir Dialog


    I ripped this code from somewhere - don't think it was here but it seems to work and I think it does what you want

    Declare Function SHBrowseForFolder Lib "shell32.dll"( ByRef lpbi As BROWSEINFO) As Long
    Declare Function SHGetPathFromIDList Lib "shell32"(ByVal pidList As Long, ByVal lpBuffer As String) As Long

    Public 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

    Function GetDirectory(Optional msg) As String
    'needs api calls SHBrowseForFolder and SHGetPathFromIDList
    'needs type statement Browseinfo

    Dim bInfo As BROWSEINFO
    Dim path As String
    Dim R As Long, X As Long, pos As Integer

    bInfo.pidlRoot = 0& ' Root folder = Desktop

    If IsMissing(msg) Then ' Title in the dialog
    bInfo.lpszTitle = "Select a folder."
    bInfo.lpszTitle = msg
    End If

    bInfo.ulFlags = &H1 ' Type of directory to return
    X = SHBrowseForFolder(bInfo) ' Display the dialog
    path = Space$(512) ' Parse the result
    R = SHGetPathFromIDList(ByVal X, ByVal path)

    If R Then
    pos = InStr(path, Chr$(0))
    GetDirectory = Left(path, pos - 1)
    GetDirectory = ""
    End If

    End Function

    Sub TestGetDir()
    Dim strMsg As String
    strMsg = "hello world"
    MsgBox GetDirectory(strMsg), , strMsgBoxTitle
    End Sub

    Hope it works for you


  3. #3
    Star Lounger
    Join Date
    Apr 2002
    Sydney Australia, New South Wales, Australia
    Thanked 0 Times in 0 Posts

    Re: Dir Dialog

    I have picked up your excellent piece of code by searching the lounge.
    My problem as originaly posted below.

    I have come to the conclusion that I need to write my own dialog and yours is an excellent start.
    However I need to display the file name (with the date appended if and when the user selects a Record Directory). I also need to let the user change the file name if they desire return that to my macro and let the macro do a SaveAs.

    I am not as expert as you and would appreciate some help.
    It would also be great if you could point me to some references which might help me to understand how you have done the browse code.

    Original Post follows:-

    Does anyone know how to create an event handeler which once run will activate a macro when the user selects save in the save as built in dialog.
    I also need to read the path the user has selected.
    In our system we have Record directories which have been set-up write only.
    The idea is that if they select a path in the system with the word Record in it the file name will be tagged with the date and hour saved prior to saving.
    This will allow them to keep several versions of the same filename as true records which cannot be altered.

    Since posting the original I have had another thought and have tried an add in to add a comand to the File Menu I have called "Save As Record"
    But I now need a way to write to the Save As Dialog / File Name Box this would be a simple solution,
    or I could create my own dialog that looks like the save as one a bit tedious.



Posting Permissions

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