View Full Version : Sleeper: Using VBA to count documents within a folder
petedw
06-27-2005, 10:09 AM
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
Norie
06-27-2005, 10:35 AM
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.
Bob Phillips
06-27-2005, 10:49 AM
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
Norie
06-27-2005, 12:18 PM
xld
Can that be adapted to count a particular file type?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.