Link to home
Start Free TrialLog in
Avatar of csehz
csehzFlag for Hungary

asked on

VBA Excel 2000 - Count number of files in directory

Dear Experts,

I am not sure in the complexity of such task, is it possible with VBA to count the number of files in a directory?

In the below example the D:\ASN directory contains three files, those are assigned to an array


Sub Test()
Dim NumberOfFiles As Integer
NumberOfFiles = 3

Dim Files(3)
Files(1) = "D:\ASN\Test1.xls"
Files(2) = "D:\ASN\Test2.xls"
Files(3) = "D:\ASN\Test3.xls"
End Sub

But of course the directory can have more files, and on different names. Could be maybe with VBA browse through a directory and getting the file names from there to the array?

I assume in this way some not fixed size of array should be used

thanks,
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Do you want all files, or only files of a particular type (e.g only .xls files)?
SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of csehz

ASKER

Rorya generally the only .xls files would be enough for my targets
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of csehz

ASKER

This works for me absolutely thanks very much, Jpaulino also for you the link