AW: Frage noch offen
20.01.2008 18:44:03
Herbert
Hallo Dieter
Danke für den Tipp, habe mir einen Code rausgezogen der funktioniert aber leider nur mit MsgBox bzw. zum übertragen in eine Zelle. Ich brauche aber die Pfadangabe in einer TextBox, die in einer UserForm steckt. Weißt Du, wie ich die entsprechende Zeile bei DirAuswahl:
If sPath "" Then MsgBox sPath
ändern muß, um den Pfad als Ergebnis in die TextBox zu bringen?
If sPath "" Then TextBox1.Value = sPath - funzt nicht.
Public 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
Declare
Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Declare
Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Sub DirAuswahl()
Dim sMsg As String, sPath As String
sMsg = "Wählen Sie bitte einen Ordner aus:"
sPath = getdirectory(sMsg)
If sPath "" Then MsgBox sPath ' Was muß hier stehen, um in meine UserFrom zu kommen?
End Sub
Function getdirectory(Optional msg) As String
Dim bInfo As BROWSEINFO
Dim Path As String
Dim r As Long, x As Long, pos As Integer
bInfo.pidlRoot = 0&
If IsMissing(msg) Then
bInfo.lpszTitle = "Wählen Sie bitte einen Ordner aus."
Else
bInfo.lpszTitle = msg
End If
bInfo.ulFlags = &H1
x = SHBrowseForFolder(bInfo)
Path = Space$(512)
r = SHGetPathFromIDList(ByVal x, ByVal Path)
If r Then
pos = InStr(Path, Chr$(0))
getdirectory = Left(Path, pos - 1)
Else
getdirectory = ""
End If
End Function
Gruß Herbert