Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Folder from Open CommonDialog

Status
Not open for further replies.

borgunit

Programmer
Mar 25, 2002
373
US
I am using API calls to use the commondialog and this is working fine. What I want to do is select a folder instead of a file and have it return the folder. Is this possible with the showopen dialog? What I am trying to accomplish is to use the same dialog to accomplish two types of opens. One for a selecting file(s) and another for folders while using the same dialog and selecting OPEN. I tried messing with filter types but nogo. Any suggestions? or will I have to bite the bullet and open the folder dialog. Thanks.
 

I have done this by specifying a default filename of "Select which directory" and then retrive the path/filename from the CD.FileName and then parse off the filename.

Good Luck

 
I have tried what you said but when I select open, the dialog still browses to the folder. Mmmm, could you give me an example maybe?
 
Here's a majorly cut-down browse for folder function. No API, no PIDLs...(but incomplete). You'll need to add a reference to the Microsoft Shell Controls and Automation library:
[tt]
|Public Function BrowseForFolder(Optional strPath As Variant) As String
Dim myShell As Shell32.Shell
Dim myFolder As Shell32.Folder

Set myShell = New Shell32.Shell
Set myFolder = myShell.BrowseForFolder(0&, "Select folder:", 0, strPath)
On Error GoTo NoSelection
BrowseForFolder = myFolder.ParentFolder.ParseName(myFolder.Title).Path
Exit Function
NoSelection:
If Err.Number = 91 Then
Err.Raise vbError + 1, "BrowseForFolder", "Cancel Pressed"
Else
Err.Raise Err.Number
End If
End Function
 

I now believe what you are trying to communicate is setting the initial directory...CD.InitDir = "Your Path"

Good Luck

 
Thanks for all of your help. I am familar with the BrowseForFolder call but I was looking to avoid it and use the OpenFile. The CD.InitDir does contain my path, but I am still required to select a file first (I was wanting to highlight a folder then select OPEN). I am going with the BrowseForFolder when I need to select a folder and OpenFile when I need to select a file. Thanks anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top