Results 1 to 11 of 11

Thread: Counter sums quantity of files in said folder but doesnt update unless double clicked

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Counter sums quantity of files in said folder but doesnt update unless double clicked

    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!
    Last edited by SamT; 10-15-2017 at 07:52 AM. Reason: Added Code Format Tags with # icon

Posting Permissions

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