Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Feb 2007
    Location
    Vienna, Wien, Austria
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    hi all,,
    i got Ken Puls count files function, which works in excel until office 2007 (see attached workbook).
    Now, as i know, the FileSearch object was removed. How do i have to change the code to run this function in excel 07 as well???

    thanks in advance,
    stef
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Here's an alternative:

    [codebox]Function CountFiles(Directory As String, Optional Ext As String = "All") As Long
    ' Function purpose: To count all the files in a directory
    ' Alternate purpose: To count all files in a directory with a specified extension

    Dim fso As Object
    Dim fld As Object
    Dim fil As Object

    ' Create the FileSystemObject
    Set fso = CreateObject("Scripting.FileSystemObject")

    ' Set the folder to look in
    Set fld = fso.GetFolder(Directory)

    If Ext = "All" Then
    ' If no file extension supplied, count all files in the folder
    CountFiles = fld.Files.Count
    Else
    ' If a file extension is supplied, count the number of files in the
    ' folder with the extension
    For Each fil In fld.Files
    If Right(fil.Name, Len(Ext)) = Ext Then
    CountFiles = CountFiles + 1
    End If
    Next fil
    End If

    ' Release the objects
    Set fil = Nothing
    Set fld = Nothing
    Set fso = Nothing
    End Function[/codebox]

  3. #3
    2 Star Lounger
    Join Date
    Feb 2007
    Location
    Vienna, Wien, Austria
    Posts
    126
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks a lot, it works fine....

Posting Permissions

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