Spitze
29.08.2008 07:37:02
Rocky
Mesch echt spitze.
hab mir erlaubt es um eine Ordnerauswahl zu erweitern:
Option Explicit
Dim FSO, FO, FU, F
Dim lRow As Long
Dim icol As Integer
Dim fd As FileDialog
Public Sub Ordner_Auflisten()
Application.ScreenUpdating = False
Set FSO = CreateObject("Scripting.FileSystemObject")
icol = 0
lRow = 0
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
If fd.Show = -1 Then
Call DateienListen(strPath:=(fd.SelectedItems(1)))
GetSubFolders (fd.SelectedItems(1))
Else
Exit Sub
End If
'ActiveSheet.UsedRange.Clear
Application.ScreenUpdating = True
MsgBox "Fertig"
End Sub
Function GetSubFolders(Pfad)
Set FO = FSO.GetFolder(Pfad)
Set FU = FO.SubFolders
On Error Resume Next
For Each F In FU
lRow = lRow + 1
icol = icol + 1
Cells(lRow, icol) = F.Name
If IsEmpty(F) Then 'Probleme beim Zugriff auf Unterordner
Cells(lRow, icol) = "!keine Leseberechtigung!"
icol = icol - 1
Else
If DateienListen(strPath:=F.Path) = False Then
Cells(lRow, icol) = "!Problem beim Dateien lesen!"
End If
End If
GetSubFolders F.Path
Next
icol = icol - 1
End Function
Private Function DateienListen(strPath As String) As Boolean
Dim objFile
On Error GoTo FEHLER
DateienListen = True
With Application.FileSearch
.NewSearch
.LookIn = strPath
.SearchSubFolders = False
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
For Each objFile In .FoundFiles
lRow = lRow + 1
Cells(lRow, icol + 1) = Replace(objFile, IIf(Right(strPath, 1) = "\", strPath, _
strPath & "\"), "")
Next
End If
End With
Exit Function
FEHLER:
'Fehler beim Auslesen des Ordners
DateienListen = False
End Function
Danke nochmal.
Rocky
PS.: 'ActiveSheet.UsedRange.Clear hatte alles wieder gelöscht - hab ich rausgenommen