Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
596to600
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
596to600
596to600
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Pfadauswahl mit Baum und Default Pfad

Pfadauswahl mit Baum und Default Pfad
14.04.2005 15:38:36
marko_ti
Hallo liebe Leute,
ich benutze die Funktion (s.u.), um einen Pfad auswählen zu lassen (Pfad = GetDirectory). Problem: ich muss immer bei der Wurzel (alle Laufwerke + Netzlaufwerke) starten - wie kann ich den Baum bei Aufruf auf einen Default Pfad setzen?
Ich weiß, bei PfadPlusFile = Application.GetOpenFilename() geht es per vorgeschaltetem ChDir "c:\DefaultPfad", aber dort muss ich auch ein File wählen - und das will ich nicht.
Danke für Eure Tips!
Gruß Marko
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

Function GetDirectory(Optional Msg As String) 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

16
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Pfadauswahl mit Baum und Default Pfad
14.04.2005 15:44:13
Franz
Hallo Marko,
ist es das, was du suchst (von K.Rola) :
Option Explicit

Sub get_Folder(Optional capt, Optional initF)
Dim objShell As Object, objFolder As Object, objItem As Object
Set objShell = CreateObject("Shell.Application")
With objShell
Set objFolder = .BrowseForFolder(0&, capt, 0, initF)
End With
If Not objFolder Is Nothing Then
Set objItem = objFolder.Self
MsgBox objItem.Path
End If
End Sub


Sub Aufruf()
Call get_Folder("Was soll ich machen?", "e:\microsoft\excel")
End Sub

Grüße
Franz
Anzeige
Mann, bist du flink! oT
14.04.2005 15:46:34
K.Rola
oT
Liegt parat, von Dir gut aufbereitet :-)))) o.t.
14.04.2005 17:33:43
Dir
PERFEKT!!!
14.04.2005 15:47:01
marko_ti
Hallo Franz,
ja, super! Genau so habe ich mir die Funktion vorgestellt :-))
Vielen Dank für die schnelle Hilfe!!!
Gruß Marko
AW: Pfadauswahl mit Baum und Default Pfad
14.04.2005 15:45:32
K.Rola
Hallo,
Option Explicit
Sub get_Folder(Optional capt, Optional initF)
Dim objShell As Object, objFolder As Object, objItem As Object
Set objShell = CreateObject("Shell.Application")
With objShell
Set objFolder = .BrowseForFolder(0&, capt, 0, initF)
End With
If Not objFolder Is Nothing Then
Set objItem = objFolder.Self
MsgBox objItem.Path
End If
End Sub
Sub Aufruf()
Call get_Folder("Was soll ich machen?", "C:\Eigene Dateien")
End Sub
Gruß K.Rola

Anzeige
nochmal Danke :-)
14.04.2005 15:50:34
marko_ti
Schneller als ich auf die erste Antwort antworten kann, ist auch schon eine zweite da :-)) Dir auch vielen Dank, K.Rola!
Gruß Marko
ABER: ich komm ja gar nicht mehr höher?!
14.04.2005 16:05:37
marko_ti
Hmm, ich hoffe ihr zwei seid noch da - denn gerade fiel mir auf, dass der Baum nun keine Möglichkeit bietet auf Ordner zuzugreifen, die über dem Startpfad liegen. Das kann ich so nun leider auch nicht nutzen... :-/
Gibt es da eine Lösung?
Gruß Marko
AW: ABER: ich komm ja gar nicht mehr höher?!
14.04.2005 16:07:10
K.Rola
Hallo,
das geht mit diesem Dialog nicht.
Gruß K.Rola
Thx&Schade.Gibt es vielleicht eine Alternative? oT
14.04.2005 16:18:04
marko_ti
?
AW: Thx&Schade.Gibt es vielleicht eine Alternative? oT
14.04.2005 16:20:20
K.Rola
Hallo,
Alternative erst ab Excel 2002.
Gruß K.Rola
AW: Thx&Schade.Gibt es vielleicht eine Alternative? oT
14.04.2005 17:12:09
Nepumuk
Hi,
stellt euch doch nicht so an. Klar geht das:


Option Explicit
Private Declare Function SHBrowseForFolder Lib "shell32" ( _
    lpbi As InfoT) As Long
Private Declare Function CoTaskMemFree Lib "ole32" ( _
    ByVal hMem As LongAs Long
Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" ( _
    ByVal lpStr1 As String, _
    ByVal lpStr2 As StringAs Long
Private Declare Function SHGetPathFromIDList Lib "shell32" ( _
    ByVal pList As Long, _
    ByVal lpBuffer As StringAs Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    ByVal lpClassname As String, _
    ByVal lpWindowName As StringAs Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
    ByVal hWnd As Long, _
    ByVal Msg As Long, _
    wParam As Any, _
    lParam As Any) As Long
  
Private Type InfoT
    hWnd As Long
    Root As Long
    DisplayName As Long
    Title As Long
    Flags As Long
    FName As Long
    lParam As Long
    Image As Long
End Type
Private Const BIF_RETURNONLYFSDIRS As Long = &H1
Private Const BIF_DONTGOBELOWDOMAIN As Long = &H2
Private Const BIF_RETURNFSANCESTORS As Long = &H8
Private Const BIF_RETURNONLYFSDIRSCREATENEW As Long = &H40
Private Const BIF_BROWSEFORCOMPUTER As Long = &H1000
Private Const BIF_BROWSEFORPRINTER As Long = &H2000
Private Const BIF_BROWSEINCLUDEFILES As Long = &H4000
Private Const BFFM_SETSELECTION = &H466
Private Const BFFM_INITIALIZED = &H1
Private s_BrowseInitDir As String
Private Function fncGetFolder( _
    Optional ByVal sMsg As String = "Bitte wählen Sie ein Verzeichnis", _
    Optional ByVal lFlag As Long = BIF_RETURNONLYFSDIRS, _
    Optional ByVal sPath As String = "C:\") As String
    Dim xl As InfoT, IDList As Long, RVal As Long, FolderName As String
    s_BrowseInitDir = sPath
    With xl
        .hWnd = FindWindow("XLMAIN", vbNullString)
        .Root = 0
        .Title = lstrcat(sMsg, "")
        .Flags = lFlag
        .FName = FuncCallback(AddressOf BrowseCallback)
    End With
    IDList = SHBrowseForFolder(xl)
    If IDList <> 0 Then
        FolderName = Space(256)
        RVal = SHGetPathFromIDList(IDList, FolderName)
        CoTaskMemFree (IDList)
        FolderName = Trim$(FolderName)
        FolderName = Left$(FolderName, Len(FolderName) - 1)
    End If
    fncGetFolder = FolderName
End Function
Private Function BrowseCallback( _
    ByVal hWnd As Long, _
    ByVal uMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As LongAs Long
    If uMsg = BFFM_INITIALIZED Then _
        Call SendMessage(hWnd, BFFM_SETSELECTION, ByVal 1&, ByVal s_BrowseInitDir)
    BrowseCallback = 0
End Function
Private Function FuncCallback(ByVal nParam As LongAs Long
    FuncCallback = nParam
End Function
Public Sub test()
    Dim sFolder As String
    sFolder = Trim$(fncGetFolder(, , "C:\Temp"))
    If sFolder <> "" Then MsgBox sFolder
End Sub


Gruß
Nepumuk
Anzeige
AW: Thx&Schade.Gibt es vielleicht eine Alternative? oT
14.04.2005 17:28:26
K.Rola
Hi Nepumuk,
AddressOf in Excel 97?
Gruß K.Rola
AW: Thx&Schade.Gibt es vielleicht eine Alternative? oT
14.04.2005 17:58:17
Nepumuk
Liebste K.Rola,
da bin ich jetzt ehrlich überfragt.
Gruß
Nepumuk
(was had a den a no a so a alds Glumb?)
AW: Thx&Schade.Gibt es vielleicht eine Alternative? oT
bst
Auch Hallo,
Siehe Jim Rech's BrowseForFolder von hier http://www.oaltd.co.uk/MVP/MVPPage.asp
Da gibt's ein AddrOf welches auch mit xl97 funktiionieren soll.
Gruß, Bernd
wieso geht das nicht?!
14.04.2005 17:17:25
IngoG
Hallo zusammen,
schönes Teil, kannte ich noch nicht...
habs einfach mal laufen lassen und bei mir (der Startpfad existiert nicht) geht er auf die unterste Ebene.
von dort ist alles erreichbar...
Gruß Ingo
Anzeige
Schon aber...
14.04.2005 17:44:19
Franz
... starte mal mit einem tieferen Ordner und versuche dann höher zu gehen...
Grüße
Franz

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige