ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   TreeView (https://www.excelbanter.com/excel-programming/296688-treeview.html)

marijan glavac[_2_]

TreeView
 
Hi,

I have big problem. I work on project in which user define folder
(directory). First I use commondialog control and to get folder user need to
select file and then press Open button.
Is there any way too get just folder (like in explorer).I have control
treeview on my mind but I dosn't know a lot about it.
Please help.

Thanks in advance.

Mrarijan



Harald Staff

TreeView
 
I have big problem. I work on project in which user define folder
(directory). First I use commondialog control and to get folder user need

to
select file and then press Open button.
Is there any way too get just folder (like in explorer).I have control
treeview on my mind but I dosn't know a lot about it.
Please help.



Hi

Let Windows take care of this for you:

'TOP OF MODULE ********************
Option Explicit

Enum BrowseForFolderFlags
BIF_RETURNONLYFSDIRS = &H1
BIF_DONTGOBELOWDOMAIN = &H2
BIF_STATUSTEXT = &H4
BIF_BROWSEFORCOMPUTER = &H1000
BIF_BROWSEFORPRINTER = &H2000
BIF_BROWSEINCLUDEFILES = &H4000
BIF_EDITBOX = &H10
BIF_RETURNFSANCESTORS = &H8
End Enum

Private Type BrowseInfo
hwndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type

Private Declare Function SHBrowseForFolder Lib _
"shell32" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib _
"shell32" (ByVal pidList As Long, _
ByVal lpBuffer As String) As Long

Private Declare Function lstrcat Lib "kernel32" _
Alias "lstrcatA" (ByVal lpString1 As String, _
ByVal lpString2 As String) As Long


Public Function BrowseForFolder(hWnd As Long, _
Optional Title As String, _
Optional Flags As BrowseForFolderFlags) As String

Dim iNull As Integer
Dim IDList As Long
Dim Result As Long
Dim Path As String
Dim bi As BrowseInfo

If Flags = 0 Then Flags = BIF_RETURNONLYFSDIRS
With bi
.lpszTitle = lstrcat(Title, "")
.ulFlags = Flags
End With

IDList = SHBrowseForFolder(bi)
If IDList Then
Path = String$(300, 0)
Result = SHGetPathFromIDList(IDList, Path)
iNull = InStr(Path, vbNullChar)
If iNull Then Path = Left$(Path, iNull - 1)
End If
BrowseForFolder = Path
End Function


Sub Test()
Dim sPath As String
sPath = BrowseForFolder(858, _
"Choose a folder:", BIF_DONTGOBELOWDOMAIN)
If sPath < "" Then MsgBox sPath
End Sub

HTH. Best wishes Harald



marijan glavac[_2_]

TreeView
 
Thanks.That is what i need.

Marijan




All times are GMT +1. The time now is 09:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com