ich suche einen Befehl, womit ich einen Dialog geöffnet bekomme, wo man aus einer Liste ein Laufwerk auswählen kann (für Auswahl des Speicherorts) und das ausgewählte laufwerk in eine Zelle schreibt bspw. a1.
Vielen Dank
Gruß Meinolf
Sub SpeichernUnter()
Application.Dialogs(xlDialogSaveAs).Show
End Sub
Gruß Tin@
Private Sub ComboBox1_GotFocus()
Dim i As Long
ComboBox1.Clear
On Error Resume Next
For i = Asc("A") To Asc("Z")
ChDrive Chr(i)
If Err = 0 Then
ComboBox1.AddItem Chr(i)
Else
Err = 0
End If
Next
On Error GoTo 0
End Sub
Private Sub ComboBox1_LostFocus()
Range("A1").Value = ComboBox1.Value
End Sub
das erste Makro ermittelt die vorhandenen Laufpfade, das 2. Makro schreibt den gewählten Wert in die Zelle zurück
Gruß, Daniel
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