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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browse folder

Status
Not open for further replies.

dejfatman

Programmer
Jan 24, 2002
34
0
0
US
Hi, I'm trying to allow an open of a file browsing window in my app. I found some code and inserted it into a module. The code looks like so:

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

Function BrowseFolder(Optional Caption As String, _
Optional InitialFolder As String) As String

Dim SH As Shell32.Shell
Dim F As Shell32.Folder

Set SH = New Shell32.Shell
Set F = SH.BrowseForFolder(0&, Caption, BIF_RETURNONLYFSDIRS, _
InitialFolder)

If Not F Is Nothing Then
BrowseFolder = F.Items.Item.Path
End If

End Function


When I tried to execute, I received "Compile error: User defined type not defined". So I figured I had to add a reference to shell32.dll in my project. However, when I went to available references, it wasn't listed. I tried to use the browse function to select it, but when I did I received "Can't add a reference to the specified file." Any ideas why?
 
Oh, I should add that we are running Winnt boxes at work.
 
I personally use this (no need for reference):
Function PickFolder(strStartDir As Variant) As String
Dim SA As Object, f As Object
Set SA = CreateObject("Shell.Application")
Set f = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
If (Not f Is Nothing) Then
PickFolder = f.Items.Item.Path
End If
Set f = Nothing
Set SA = Nothing
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks, but I'm still having problems. I plugged your code and got a Runtime error 429: ActiveX component can't create object on your statement Set SA = CreateObject("Shell.Application")
 
I think it is the Microsoft Shell Controls and Automation library, but could you instead try API?

Here's a nice wrapper BrowseFolder Dialog

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top