Дайте этому попытку
Sub Test_CountFiles_UDF()
CountFiles ThisWorkbook.Path & "\MyFolder\", "xls*,doc*"
Debug.Print "--------"
CountFiles ThisWorkbook.Path & "\MyFolder\", "xls*,doc*", "finance"
End Sub
Sub CountFiles(sPath As String, sExtensions As String, Optional sFindText As String)
Dim arrTypes, strFile As String, i As Long, c As Long
arrTypes = Split(sExtensions, ",")
For i = 0 To UBound(arrTypes)
c = 0
strFile = Dir(sPath & "*." & arrTypes(i))
Do While strFile <> ""
If Not IsMissing(sFindText) And sFindText <> "" Then
If InStr(LCase(strFile), LCase(sFindText)) Then c = c + 1
Else
c = c + 1
End If
strFile = Dir
Loop
Debug.Print arrTypes(i) & ": " & c
Next i
End Sub