By using expertatexcel.com you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes

expertatexcel.com

 


CountFiles(sDir, sFilter)


Function Countfiles(sDir, sFilter)

CountFiles = 0

if Right(sDir, 6) = ".xlsx\" Then
   sFile = Dir(Left(sDir, Len(sDir) - 1)
   If sFile <> "" Then
      CountFiles = 1
   End If
   Exit Function
End If

If Right(sDir, 1) = "/" Then
  'ok
Else
   sDir = sDir & "/"
End If

sFile = Dir(sDir & "*" & sFilter
Do While sFile <> ""
   Countfiles = Countfiles + 1

   sFile = Dir
Loop

End Function