Option Compare Text
Option Explicit
Function CountFiles(Directory As String) As Double
'Function purpose: To count all files in a directory
Dim fso As Object, _
objFiles As Object
'Create objects to get a count of files in the directory
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set objFiles = fso.GetFolder(Directory).Files
If Err.Number <> 0 Then
CountFiles = 0
Else
CountFiles = objFiles.Count
End If
On Error GoTo 0
End Function
Sub TestCount()
'To demonstrate the use of the CountFiles function
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.folderexists(Selection) Then
MsgBox "I found " & CountFiles(Selection) & " files in " & Selection, _
vbOKOnly + vbInformation, CountFiles(Selection) & " files found!"
Else
MsgBox "Sorry, but I can't find the folder: " & vbCrLf & Selection _
& vbCrLf & "Please select a cell that has a valid" & vbCrLf & _
"folder name in it!", vbOKOnly + vbCritical, "Error!"
End If
End Sub
How do I get this to refresh or auto update?
Also I have no Idea what I'm doing as this script was pinched from another user of this fine website and community!