ist es möglich, per VBA die Anzahl der Ordner zu zählen, die sich in einem Verzeichnis befinden?
also ich möchte wissen, wieviele Ordner (ohne weitere Unterordner) befinden sich in C:\Test
Gruß
Steffen
Sub DateienAuflisten()
Dim i As Long
Const verz = "C:\Users\Ing.Grohn\Documents\" '"C:\Eigene Dateien\"
Load UF_Dateiliste
On Error GoTo Fehler
ChDir verz
Sheets("Tabelle1").Activate
Range("A1").Select
With Application.FileSearch
.NewSearch
.LookIn = verz
.SearchSubFolders = False
.FileType = msoFileTypeAllFiles
.Execute
For i = 1 To .FoundFiles.Count
cells(i,1).value= .FoundFiles(i)
Next i
End With
UF_Dateiliste.Show
Exit Sub
Fehler:
MsgBox "Es gibt kein Verzeichnis mit dem Namen " & verz
'msofileType kann eine der folgenden MsoFileType-Konstanten sein:
'msofileTypeAllFiles
'msofileTypeBinders
'msofileTypeCalendarItem
'msofileTypeContactItem
'msofileTypeCustom
'msofileTypeDatabases
'msofileTypeDataConnectionFiles
'msofileTypeDesignerFiles
'msofileTypeDocumentImagingFiles
'msofileTypeExcelWorkbooks
'msofileTypeJournalItem
'msofileTypeMailItem
'msofileTypeNoteItem
'msofileTypeOfficeFiles
'msofileTypeOutlookItems
'msofileTypePhotoDrawFiles
'msofileTypePowerPointPresentations
'msofileTypeProjectFiles
'msofileTypePublisherFiles
'msofileTypeTaskItem
'msofileTypeTemplates
'msofileTypeVisioFiles
'msofileTypeWebPages
'msofileTypeWordDocuments
End Sub
Option Explicit
Sub AnzVerz()
Dim strT As String, lngA As Long
Const strVz As String = "c:\test\"
strT = Dir(strVz, vbDirectory)
If strT "" Then
If strT "." And strT ".." And _
(GetAttr(strVz & strT) And vbDirectory) = vbDirectory Then
lngA = lngA + 1
' Debug.Print lngA & " " & strT
End If
While strT ""
If strT "." And strT ".." And _
(GetAttr(strVz & strT) And vbDirectory) = vbDirectory Then
lngA = lngA + 1
' Debug.Print lngA & " " & strT
End If
strT = Dir
Wend
End If
MsgBox lngA & " Verzteichnisse in " & strVz
End Sub
Option Explicit
Sub AnzVerz2()
Dim strT As String, lngA As Long
Const strVz As String = "f:\exc\"
strT = Dir(strVz, vbDirectory)
While strT ""
If strT "." And strT ".." And _
(GetAttr(strVz & strT) And vbDirectory) = vbDirectory Then
lngA = lngA + 1
Debug.Print lngA & " " & strT
End If
strT = Dir
Wend
MsgBox lngA & " Verzteichnisse in " & strVz
End Sub
Rückmeldung wäre nett! - Grüße von Erich aus Kamp-Lintfort