AW: Userform per Variable aufrufen
21.07.2005 16:48:48
Conny
Hallo Rainer,
danke für Deine Antwort, aber irgendwie weiß ich noch nicht wie ich Deinen Tip einbauen soll ... hier der Code, vielleicht kannst Du mir hier auch weiterhelfen?
Im Initialize-Ereignis der Userform11 steht:
Dim alleOrdner As String
alleOrdner = Sheets("vip").Range("b304").Value
Set TreeView1.ImageList = ImageList1
FillTreeView (alleOrdner)
im Modul:
' TreeView mit allen Ordnern eines Laufwerks füllen
Public Sub FillTreeView(ByVal StartPath As String)
Dim DirName As String
Dim i As Integer
Dim sPos As Integer
Dim ordner As String
Dim MainOrdner As String
' TreeView löschen
UserForm11.TreeView1.Nodes.Clear
' Verzeichnisse ermitteln
If Right$(StartPath, 1) = ":" Then _
StartPath = StartPath + "\"
GetAllFolders StartPath
' Erster Eintrag: Laufwerk selbst
UserForm11.Nodes.Add , , StartPath, StartPath, 3, 3
End With
' Verzeichnisse
While UserForm11.ListBox8.ListCount > 0
DirName = UserForm11.ListBox8.List(0)
userrform11.ListBox8.RemoveItem 0
sPos = InstrRev97(DirName, "\")
ordner = Mid$(DirName, sPos + 1)
MainOrdner = Left$(DirName, sPos - 1)
If InStr(MainOrdner, "\") = 0 Then _
MainOrdner = MainOrdner + "\"
UserForm11.TreeView1.Nodes.Add MainOrdner, tvwChild, DirName, ordner, 1, 2
Wend
' Root öffnen
UserForm11.TreeView1.Nodes(1).Expanded = True
End Sub
' Rekursive Prozedur zum Ermitteln aller Verzeichnisse
Private Sub GetAllFolders(ByVal pfad As String)
Dim Count As Long
Dim i As Long
Dim DirName() As String
On Local Error Resume Next
Count = GetAllSubDir(pfad, DirName())
i = 1
Do Until i > Count
UserForm11.ListBox8.AddItem pfad + DirName(i)
GetAllFolders pfad + DirName(i) + "\"
i = i + 1
Loop
On Local Error GoTo 0
End Sub
' Unterverzeichnisse eines Ordners ermitteln
Private Function GetAllSubDir(Path As String, _
D() As String) As Integer
Dim DirName As String
Dim Count As Integer
DirName = Sheets("vip").Range("b304").Value
If Right$(Path, 1) <> "\" Then Path = Path + "\"
DirName = Dir(Path, vbDirectory)
Count = 0
Do While DirName <> ""
If DirName <> "." And DirName <> ".." Then
If (GetAttr(Path + DirName) And vbDirectory) = _
vbDirectory Then
If (Count Mod 10) = 0 Then
ReDim Preserve D(Count + 10) As String
End If
Count = Count + 1
D(Count) = DirName
End If
End If
DirName = Dir
Loop
GetAllSubDir = Count
End Function
Wie kann ich nun "Userform11" durch eine Variable ersetzten?
Danke für Deine Hilfe!
Conny