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

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:46
Joined
Feb 19, 2002
Messages
33,677
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.
 

Attachments

  • SampleWordAutomation_20210314.zip
    306.1 KB · Views: 22

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 07:46
Joined
May 7, 2009
Messages
14,555
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:

Code:
Dim fpath As String
Dim col     As New Collection

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

'arnelgp
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