AW: Laufwerk auswählen mit Dialog
31.08.2008 23:24:00
Tino
Hallo,
ich habe das hier gefunden.
Option Explicit
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
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
'Ruft das Dialogfeld zur Ordnerauswahl auf
Function GetDirectory(Msg) As String
Dim bInfo As BROWSEINFO
Dim path As String
Dim r As Long, x As Long, pos As Integer
With bInfo
.pidlRoot = 0&
.lpszTitle = Msg
.ulFlags = &H1
End With
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)
GetDirectory = IIf(Right$(GetDirectory, 1) = "\", GetDirectory, GetDirectory & "\")
Else
GetDirectory = ""
End If
End Function
'Hier ein Beispiel für die Verwendung**********************
Sub Auswahl()
Dim strLW As String
strLW = GetDirectory("Bitte einen Ordner wählen") '& "\"
End Sub
Gruß Tino
www.VBA-Excel.de