Consulting

Results 1 to 2 of 2

Thread: count files extension

  1. #1

    count files extension

    hi all,

    my boss ask me to count how many file in a folder/
    when i search i got link http://www.vbaexpress.com/kb/getarticle.php?kb_id=247
    but when i run it, i get bug
    "object doesn't support this action" and when i press debug go to:
    Set fs = Application.FileSearch

    how to solve this, or maybe someone have others macro or tools to count how many files in a folder?

    i use office 2010.

    many thanks

    reza

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    FileSearch was removed in 2007 which is more the pity.

    [VBA]Sub Test_CountFilesInFolder()
    MsgBox CountFilesInFolder(ThisWorkbook.Path)
    End Sub

    '=CountFilesInFolder("c:\")
    Function CountFilesInFolder(pFolder As String) As Long
    Rem Needs Reference: MicroSoft Scripting Runtime, scrrun.dll
    Rem Instructions: http://support.microsoft.com/default...b;en-us;186118
    Dim FSO As New FileSystemObject
    Dim i As Long

    With FSO
    'Exit if parent folder does not exist.
    If Not .FolderExists(pFolder) Then
    MsgBox pFolder & " does not exist.", vbCritical, "Macro Ending"
    Exit Function
    End If

    i = .GetFolder(ThisWorkbook.Path).Files.Count
    End With
    Set FSO = Nothing
    CountFilesInFolder = i
    End Function
    [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •