Solved Access VBA - Loop through files in Folders, Subfolders, Sub-Sub Folders.... (1 Viewer)

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:57
Feb 19, 2002
If you still don't have this working, here's another working example. Press the "Show me the Tool" button on the second form. This sample is about Word automation so has nothing to do with your problem. The "tool" is a form I used to read through a bunch of word docs to collect all the bookmarks. There is an option group on the form that tells whether to search just the selected folder or drill down to all folders below the chosen one. Uploading the whole thing means I don't have to extract the relevant parts and risk breaking the "tool" in the process.


    306.1 KB · Views: 80


..forever waiting... waiting for jellybean!
Local time
Today, 17:57
May 7, 2009
it is a Sub, so it will not Return anything.
what you need is to pass your Collection to the Sub
and the Collection will be "filled" when the
Sub finished:

Dim fpath As String
Dim col     As New Collection

fpath = "\\Drive\Home\Desktop\"

Call RecursiveDir(col, fpath, "*.*", True)

Debug.Print col.count
  'returns zero every time, fpath is valid and has several files/folders

Users who are viewing this thread

Top Bottom