Recursive Function

creyn

Board Regular
Joined
Sep 16, 2016
Messages
127
Is it possible to pull files based on date using the Recursive Function? Below is the code I am using
Code:
Option Compare Database

Public Sub Command0_Click()
Dim MyFolder As String
Dim MyFile As String
Dim MyFolder2 As String
Dim DQ As String
Dim MyData As String
Dim myQueryName As String
Dim myExportFileName As String
Dim fso As Object
Dim fld As Folder
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
    .Title = ""
    .AllowMultiSelect = False
    intialfilename = ""
    
    If .Show = True Then
        For Each varfile In .SelectedItems
            strFolder = varfile
        Next
    Else
        rtn = SysCmd(4, "Action aborted by user")
        Exit Sub
      End If
    End With
    
    txtfolder = strFolder
    
    Set fso = New FileSystemObject
    Set fld = fso.GetFolder(strFolder)
    RecursiveSearch fld
End Sub
Private Sub RecursiveSearch(fld As Folder)
Dim fold As Folder
Dim sysdate As Date
Dim fil As File
Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant
    For Each fold In fld.SubFolders
        txtresults = txtresults & "Folder:  " & fold.Path & "" & vbCrLf
        RecursiveSearch fold
    Next
    For Each fil In fld.Files
        txtresults = txtresults & "File:      " & fil.Path & vbCrLf
 Next
End Sub
 
Last edited by a moderator:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
you might want to take a look at Allen Browne's code for this as I'd trust it more than what you have. Firstly, because you don't seem to have Option Explicit as your default, which some would say means that you deserve what you get. In support of this notion, I see that you are using but have not declared at least one variable or object, strFolder.
 
Upvote 0
I will try the Allen Browne's code. Hopefully I can get it to only bring back the dates for the files I am looking for.
 
Upvote 0

Forum statistics

Threads
1,221,787
Messages
6,161,960
Members
451,734
Latest member
Anmol Pandey19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top