pick a folder

P

Pablo Cardellino

Hi,

I'm looking for a method for ask the user to pick a folder within the
filesystem, using a standard Word dialog, such as the wdDialogFileOpen,
but I don't need to open anything: just picking the path of the selected
directory.

Any help would be appreciated.

Best regards,
 
J

Jay Freedman

Hi,

I'm looking for a method for ask the user to pick a folder within the
filesystem, using a standard Word dialog, such as the wdDialogFileOpen,
but I don't need to open anything: just picking the path of the selected
directory.

Any help would be appreciated.

Best regards,

Hi Pablo,

The SHBrowseForFolder function is supplied in the Windows API in shell32.dll.
Sample code to call it from VBA is given in
http://www.developerfusion.com/code/2127/browse-for-folder-vba/ and a number of
other places on the Web
(http://www.google.com/search?hl=en&rls=GGLD,GGLD:2008-28,GGLD:en&q=SHBrowseForFolder+vba&btnG=Search).
There's a class that enhances the API at
http://ccrp.mvps.org/controls/ccrpbdsvr6.htm, although using it will mean that
you have to distribute its DLL along with your template.
 
T

Tony Jollans

With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then
SelectedFolder = .SelectedItems(1)
Else
SelectedFolder = ""
End If
End With

MsgBox "You selected " & IIf(SelectedFolder = "", "nothing", SelectedFolder)
 
P

Pablo Cardellino

Tony Jollans escribió:
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then
SelectedFolder = .SelectedItems(1)
Else
SelectedFolder = ""
End If
End With

MsgBox "You selected " & IIf(SelectedFolder = "", "nothing",
SelectedFolder)

Great Tony, very simple.

Thanks a lot
 
P

Pablo Cardellino

Thanks, Jay

Jay Freedman escribió:
Hi Pablo,

The SHBrowseForFolder function is supplied in the Windows API in shell32.dll.
Sample code to call it from VBA is given in
http://www.developerfusion.com/code/2127/browse-for-folder-vba/ and a number of
other places on the Web
(http://www.google.com/search?hl=en&rls=GGLD,GGLD:2008-28,GGLD:en&q=SHBrowseForFolder+vba&btnG=Search).
There's a class that enhances the API at
http://ccrp.mvps.org/controls/ccrpbdsvr6.htm, although using it will mean that
you have to distribute its DLL along with your template.


--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
 

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