File Folder Browse Dialog

S

Sean

How can I access a file folder browse/select dialog box after clicking on a
button (say btnFolderSelect). I searched the forum for an answer and there
is a method which accesses shell32.shell. That didn't work and i'm assuming
there is an easier way to do this such as using a built in dialog (like
Dialogs(wdDialogInsertPicture) )? Is there a built in dialog for Browsing
folders? And if so can you set a default location?

Thanks for the help...
 
E

Ed

Do you want to browse through all available folders and just select a
folder? Or do you want to select a folder and then browse through the
folder for a specific file? Anything using shell32 requires a reference to
Microsoft Shell Controls And Automation. Browsing for a specific file is
done very easily using built-in dialogs - see Help for more info.

Ed
 
S

Sean

I'd like to be able to browse through all available folders to select a
folder. (It will be used as a user-specified Save To: path.) Is this
possible with built-in dialogs?
 
J

Jonathan West

E

Ed

Sean: To select one folder, I use the following code. For my purposes,
strLookIn in the function is declared to be used by all subs in the module,
and is where I store the folder path.

HTH
Ed

Sub GetFolder()

GetFolderName ("Choose a folder")

End Sub

Function GetFolderName(sCaption As String) As String
'Needs a reference to (Tools > Reference)
'Microsoft Shell Controls And Automation
Dim oShell As Shell32.Shell
Dim oFolder As Shell32.Folder
Dim oItems As Shell32.FolderItems
Dim Item As Shell32.FolderItem

On Error GoTo CleanUp

Set oShell = New Shell
Set oFolder = oShell.BrowseForFolder(0, sCaption, 0)
Set oItems = oFolder.Items
Set Item = oItems.Item

GetFolderName = Item.Path
strLookIn = Item.Path

CleanUp:
Set oShell = Nothing
Set oFolder = Nothing
Set oItems = Nothing
Set Item = Nothing

End Function
 
S

Sean

Using the "Copy" dialog will work for me. But I have one question... When a
directory is selected and I display the path in a textbox, the directory path
is displayed with quotes "" on both ends. How can I get rid of the quotes
?... either by not capturing them or by trimming them from the text before it
is displayed?
 
J

Jonathan West

Run the returned string through this function

Function TrimQuotes(strQuotes As String) as String
If Asc(strQuotes) = 34 Then
TrimQuotes = Mid$(strQuotes, 2, Len(strQuotes) - 2)
Else
TrimQuotes = strQuotes
End If
End Function


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
M

Michael Bednarek

How can I access a file folder browse/select dialog box after clicking on a
button (say btnFolderSelect). I searched the forum for an answer and there
is a method which accesses shell32.shell. That didn't work and i'm assuming
there is an easier way to do this such as using a built in dialog (like
Dialogs(wdDialogInsertPicture) )? Is there a built in dialog for Browsing
folders? And if so can you set a default location?

At least in Word11, there is the FileDialog object. Doesn't that do what
you want?

With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then
MsgBox .SelectedItems(1)
Else
MsgBox "Nothing selected."
End If
End With
 

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