Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > PC based Database Applications > Microsoft Excel > How to list all the files in a folder?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-15-08, 12:02
pepemosca pepemosca is offline
Registered User
 
Join Date: Apr 2008
Posts: 167
Question How to list all the files in a folder?

Hello,
I would like to know how in VBA to list all the files that are on a specific folder.

Like doing a "DIR *.*", and getting the result on some collection or array or something like that.

Also, is there any way to recognize if is it a folder or a file the content of the path?

Thanks in advance for your help.

Saludos,
pepemosca
Reply With Quote
  #2 (permalink)  
Old 06-15-08, 21:00
shades shades is offline
Registered User
 
Join Date: Oct 2003
Posts: 1,080
Howdy. If you go to www.vbaexpress.com and register (great site - many fantastic coders and Excel experts), they have many articles, some of them already have the code written for you to use.
__________________
old, slow, and confused
but at least I'm inconsistent!

Rich
(retired Excel 2003 user, 3/28/2008)

How to ask a question on forums
Reply With Quote
  #3 (permalink)  
Old 06-16-08, 10:44
pepemosca pepemosca is offline
Registered User
 
Join Date: Apr 2008
Posts: 167
Great reference!
Thank you for your suggestion.

BTW, I've found the solution here
http://vbaexpress.com/kb/getarticle.php?kb_id=733
http://vbaexpress.com/kb/getarticle.php?kb_id=781
http://vbaexpress.com/kb/getarticle.....php?kb_id=837

I just post the links, to leave a reference at dBforums, but as you said: you must be registered at VBA Express to be able to see the code.

All the abobe are for Excel VBA 2003

Last edited by pepemosca : 06-16-08 at 12:27.
Reply With Quote
  #4 (permalink)  
Old 06-16-08, 11:52
pepemosca pepemosca is offline
Registered User
 
Join Date: Apr 2008
Posts: 167
Oh, too bad.
The "Application.FileSearch" doesn't work with Excel 2007

I need to make a new Google Search :P
Reply With Quote
  #5 (permalink)  
Old 06-16-08, 12:06
pepemosca pepemosca is offline
Registered User
 
Join Date: Apr 2008
Posts: 167
Here is some code that works:
http://www.ozgrid.com/forum/showpost...50&postcount=5

Code:
Sub testit() myvar = FileList(ActiveWorkbook.Path) If TypeName(myvar) <> "Boolean" Then For i = LBound(myvar) To UBound(myvar) Cells(i + 1, 1).Value = myvar(i) Next Else MsgBox "No files found" End If End Sub Function FileList(fldr As String, Optional fltr As String = "*.*") As Variant Dim sTemp As String, sHldr As String If Right$(fldr, 1) <> "\" Then fldr = fldr & "\" sTemp = Dir(fldr & fltr) If sTemp = "" Then FileList = False Exit Function End If Do sHldr = Dir If sHldr = "" Then Exit Do sTemp = sTemp & "|" & sHldr Loop FileList = Split(sTemp, "|") End Function
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On