Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

count files in specific folder and display the number into 1 cel [closed]

Tags:

file

vba

xls

I am trying to know how many files there are in 1 specific folder with .xls extension. I read hundreds of examples with message boxes, but that is not what I'm looking for. I just want to have the number displayed into 1 cel.

Is there someone who likes to help me with that please? I can not post any attempts because I can not get started :-(

best regards, E.

like image 391
user2151190 Avatar asked May 25 '13 20:05

user2151190


People also ask

How do I count the number of files in a folder?

Alternatively, select the folder and press the Alt + Enter keys on your keyboard. When the Properties window opens, Windows 10 automatically starts counting the files and folders inside the selected directory. You can see the number of files and folders displayed in the Contains field.


1 Answers

Try below code :

Assign the path of the folder to variable FolderPath before running the below code.

Sub sample()

    Dim FolderPath As String, path As String, count As Integer
    FolderPath = "C:\Documents and Settings\Santosh\Desktop"

    path = FolderPath & "\*.xls"

    Filename = Dir(path)

    Do While Filename <> ""
       count = count + 1
        Filename = Dir()
    Loop

    Range("Q8").Value = count
    'MsgBox count & " : files found in folder"
End Sub
like image 196
Santosh Avatar answered Dec 10 '22 10:12

Santosh