Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 128
Default Select Folder - Simples Method

What is the best method to allow the user to select a folder?

I have found some example pieces of code to do this but they all seem to
involve a lot of code.

Is there an equivalent of the .GetOpenFilename function for Folders? or do
you use this method then remove the selected filename from the string?



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Select Folder - Simples Method

With Excel XP you can use

With Application.FileDialog(msoFileDialogFolderPicker)
.Show
MsgBox .SelectedItems(1)


End With

with earlier versions



Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long


Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" _
(lpBrowseInfo As BROWSEINFO) As Long


Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type


'-------------------------------------------------------------
Function GetFolder(Optional ByVal Name As String = _
"Select a folder.") As String
'-------------------------------------------------------------
Dim bInfo As BROWSEINFO
Dim path As String
Dim oDialog As Long


bInfo.pidlRoot = 0& 'Root folder = Desktop


bInfo.lpszTitle = Name


bInfo.ulFlags = &H1 'Type of directory to Return
oDialog = SHBrowseForFolder(bInfo) 'display the dialog


'Parse the result
path = Space$(512)


GetFolder = ""
If SHGetPathFromIDList(ByVal oDialog, ByVal path) Then
GetFolder = Left(path, InStr(path, Chr$(0)) - 1)
End If


End Function




--
HTH

Bob Phillips

"Andibevan" wrote in message
...
What is the best method to allow the user to select a folder?

I have found some example pieces of code to do this but they all seem to
involve a lot of code.

Is there an equivalent of the .GetOpenFilename function for Folders? or

do
you use this method then remove the selected filename from the string?





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
transformar nĂºmero simples em datas correntes glasner Excel Discussion (Misc queries) 1 October 30th 06 08:49 PM
How to decide folder-depth or How to select more folders/subfolders (folder-tree) ? Subteam Excel Discussion (Misc queries) 2 May 7th 06 08:14 PM
Select Folder - Simples Method Andibevan[_2_] Excel Programming 5 June 30th 05 07:18 PM
Select Method of Sheets Brenda Meza via OfficeKB.com Excel Programming 2 May 20th 05 12:37 AM
Help with Select Case or Best Method Christina[_4_] Excel Programming 1 November 5th 03 06:15 PM


All times are GMT +1. The time now is 03:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"