Function Countfiles(sDir, sFilter)CountFiles = 0if 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 'okElse sDir = sDir & "/"End If sFile = Dir(sDir & "*" & sFilterDo While sFile <> "" Countfiles = Countfiles + 1 sFile = DirLoopEnd Function