File/Folder Browser on a UserForm

J

John

Is there a way to put a File/Folder Browser on a UserForm? The Control
Toolbox doesn't have one.
 
D

Doug Robbins

I use the following to load a textbox (txtFldrPath) on a userform with the
folder selected by the user when they click on a Browse button
(btnBrowseforFolder):

Private Sub btnBrowseforFolder_Click()
Dim SH As Shell32.Shell
Dim Fldr As Shell32.Folder
Set SH = New Shell32.Shell
Set Fldr = SH.BrowseForFolder(0, "Select folder in which to save the files",
&H400)
If Not Fldr Is Nothing Then
txtFldrPath.Text = Fldr.Items.Item.Path & "\"
End If
Set Fldr = Nothing
End Sub

It is necessary to have a reference set to the Microsoft Shell Controls and
Automation object library.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

John

Thanks for you help Doug.

Is there a way to set the Browse for Folder so that it has a certain
folder pre-selected (my current default folder)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top