'Attribute VB_Name = "OpenOrCount"
'Open Count File'
Option Explicit
' ---------------------------------------------------------
' Änderungs-History:
' ---------------------------------------------------------
' ---------------------------------------------------------
' Funktion: CountAll
' Eingestellt von: Andre Schau
' Datum: 5. Juno 2006
' Kommentar: Extension wid als beliebiger Substring gewertet
' Parameter: Pfad :\\und Typ *.
' Rückgabe: Erfolg: Anzahl, sonst Anzahl und Err.Number
' Aufruf:
' Sub CountFiles()
' MsgBox CountAll("C:\Test\", "*.xls") ',True
' End Sub
' ---------------------------------------------------------
Option Explicit
Private Function CountAll(ByVal sPath$, ByVal sType$, Optional ByVal bOpen As BooleanAs String
'Stringvariablen
Dim sFiles$
'Integervariablen
Dim iCounter%
On Error Goto errorhandler
'Einträge mit Dir auslesen
sFiles = Dir(sPath$ & sType)
'Schleife über alle Einträge, Counter hochzählen
Do While sFiles <> ""
  iCounter = iCounter + 1
  If bOpen Then Workbooks.Open (sPath & sFiles)
  sFiles = Dir(sPath$ & sType)
Loop
CountAll = iCounter
Exit Function
errorhandler:
CountAll = iCounter & "," & Err.Number
End Function