how do i use a dialog to find just a path (not a file) ?
how do i use a dialog to find just a path (not a file) ?
(OP)
I'd like to use a dialog box to allow the user to find the path to a set of folders but what i've seen so far seems to only work when you select a file (otherwise the 'open' or 'save' button remains greyed out.
Is there any way to use a dialog to allow the user to select just the path without having to select a file?
In this instance i'm using Excel 97 SR-2
Thanks in Advance
Ian
Is there any way to use a dialog to allow the user to select just the path without having to select a file?
In this instance i'm using Excel 97 SR-2
Thanks in Advance
Ian





RE: how do i use a dialog to find just a path (not a file) ?
'32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) 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
public sub DoSomething()
'Prompt user to select folder
Dim lFolder As String
lFolder = GetDirectory("Select the folder")
If (lFolder = "") Then
Exit Sub
End If
MsgBox "You picked: " & lFolder
end sub
Public Function GetDirectory(Optional Msg) As String
Dim bInfo As BROWSEINFO
Dim path As String
Dim r As Long, x As Long, pos As Long
' Root folder = Desktop
bInfo.pidlRoot = 0&
' Title in the dialog
If IsMissing(Msg) Then
bInfo.lpszTitle = "Select a folder."
Else
bInfo.lpszTitle = Msg
End If
' Type of directory to return
bInfo.ulFlags = &H1
' Display the dialog
x = SHBrowseForFolder(bInfo)
' Parse the result
path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
GetDirectory = Left(path, pos - 1)
Else
GetDirectory = ""
End If
End Function