unter Recherche entdeckte ich folgenden Code, der mir über Directory den Pfad eines jeweiligen Ordners in einer MsgBox anzeigt. Wie müßte der Code verändert werden, damit nach Anzeige der MsgBox der jeweilige Pfad in einem ausgeblendeten Tabellenblatt "Basis", Zelle "A3" gespeichert wird und ggfs., sofern sich bereits darin Inhalt befindet, ohne Rückfrage überschrieben wird. Danke schon jetzt für die Rückmeldung und schon jetzt auch allen frohe und erholsame Feiertage.
Herzliche Grüße
Wolfgang
'zeigt den jeweiligen Pfad eines Ordners an
Option Private Module
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
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