Consulting

Results 1 to 4 of 4

Thread: Sleeper: Using VBA to count documents within a folder

  1. #1
    VBAX Regular
    Joined
    Apr 2005
    Posts
    86
    Location

    Sleeper: Using VBA to count documents within a folder

    Is there a way of telling vba to count all the word documents (.doc) in a folder and its subfolders and to refresh every 5 seconds to keep an up to date count?

    I need it for a sum that i am doing. The reason i need it to refresh is that there are constantly word documents added into these folders.

    Many Thanks

    Pete

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Is this user defined function any use?
    Function Countword(strDir As String, bSubs As Boolean) As Long
        With Application.FileSearch
            .NewSearch
            .LookIn = strDir
            .Filename = "*.doc"
            .SearchSubFolders = bSubs
            .Execute
            Countword = .FoundFiles.Count
        End With
    End Function
    Use it in a worksheet like this:
    =CountWord("C:\", FALSE)
    Change FALSE to TRUE to search sub folders.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by petedw
    Is there a way of telling vba to count all the word documents (.doc) in a folder and its subfolders and to refresh every 5 seconds to keep an up to date count?
    Dim oFSO As Object
    Set oFSO = CreateObject("Scripting.FilesystemObject")
        Debug.Print oFSO.getfolder("C:\myTest").Files.Count

  4. #4
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    xld

    Can that be adapted to count a particular file type?

Posting Permissions

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