Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Nov 2002
    Location
    London, Gtr London, England
    Posts
    496
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Using Inbuilt dialogue boxes (Word 2K)

    Dear Woodytes

    I want to create a small routine to print the contents of a given directory e.g. file name, file type, date saved etc.

    Is it possible to use an inbuilt dialogue box such as the one used by FileSaveAs to enable directory selection, if so how and how do handle the user selection, where do i find the definition of the dialogue fields?

    thank you................... liz

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Using Inbuilt dialogue boxes (Word 2K)

    Hi Liz,

    There are several ways to let the user select a folder. Here is one using Windows API's. Put the following code into a standard module:

    <img src=/w3timages/blueline.gif width=33% height=2>

    Private 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

    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 Const BIF_RETURNONLYFSDIRS = &H1

    Public Function BrowseFolder(szDialogTitle As String) As String
    Dim bi As BROWSEINFO, dwIList As Long
    Dim szPath As String, wPos As Integer

    With bi
    .lpszTitle = szDialogTitle
    .ulFlags = BIF_RETURNONLYFSDIRS
    End With

    dwIList = SHBrowseForFolder(bi)
    szPath = Space$(512)

    If SHGetPathFromIDList(ByVal dwIList, ByVal szPath) Then
    wPos = InStr(szPath, Chr(0))
    BrowseFolder = Left$(szPath, wPos - 1)
    End If
    End Function

    <img src=/w3timages/blueline.gif width=33% height=2>

    You can use this in your code as follows:

    Dim strFolder As String
    strFolder = BrowseFolder("Select a folder")
    If strFolder <> "" Then
    ' Do something with selected folder
    MsgBox "You selected " & strFolder, vbInformation
    End If

  3. #3
    4 Star Lounger
    Join Date
    Nov 2002
    Location
    London, Gtr London, England
    Posts
    496
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Using Inbuilt dialogue boxes (Word 2K)

    Hans,

    Once again, thank you it works beautifully, now all I have to do is understand what you're doing!!!

    liz

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Using Inbuilt dialogue boxes (Word 2K)

    >> now all I have to do is understand what you're doing

    If only I knew... <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>
    Functions like SHBrowseForFolder are the low-level functions Microsoft has built into the Windows operating system. Using them, you can control almost any aspect of Windows, but their interface is meant for programmers, not for end users. A function such as BrowseFolder is a "wrapper" around the low-level function that hides the ugly technical details.

    There is a simpler way to do it pointed out by Don Ceraso in <post#=271140>post 271140</post#>:

    Public Function BrowseFolder(Optional Title As String = "Select a Folder", Optional RootFolder As Variant) As String
    On Error Resume Next
    BrowseFolder = CreateObject("Shell.Application").BrowseForFolder( 0, Title, 0, RootFolder).Items.Item.Path
    End Function

    Use it the same way as the function I posted.

    You need to have Internet Explorer 4.0 or later for this.

  5. #5
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using Inbuilt dialogue boxes (Word 2K)

    Slightly off-topic, but a very, *very* basic dialog that lets you create a directory is
    Dialogs(wdDialogToolsCreateDirectory).Show

    (Probably still in Word from Word 1 times)

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

Posting Permissions

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