Extract .xls or .xlsm files within a folder and sub-folder

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I have a macro to extract excel files from c:\PULL as well as sub-folder within pull that are .xls or .xlsm


The .xls or being extracted but not the .xlsm if there is an xlsm file


Kindly amend my code below


Code:
 Sub List_Man_Acc_FileNames()

Sheets("file names").Range("A1:C150").ClearContents
Application.ScreenUpdating = False
Sheets("file names").Range("A1:C1").Value = Array("File Name", "Created", "Last Modified")

LoopController ("C:\pull")
Sheets("file names").Columns.AutoFit

End Sub

Private Sub LoopController(sSourceFolder As String)
'This will loop into itself, first processing the files in the folder
'then looping into each subfolder deeper and deeper until all folders processed
Dim Fldr As Object, FL As Object, SubFldr As Object

    Call ListFilesinFolder(sSourceFolder & Application.PathSeparator)

    Set Fldr = CreateObject("Scripting.FileSystemObject").GetFolder(sSourceFolder)
    For Each SubFldr In Fldr.SubFolders
        LoopController SubFldr.path
    Next

End Sub

Sub ListFilesinFolder(MyPath As String)
Dim FSO As Object, f As Object, FLD As Object, NR As Long

NR = Sheets("file names").Range("A" & Rows.Count).End(xlUp).Row
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FLD = FSO.GetFolder(MyPath).Files

For Each f In FLD
    If InStr(f.Name, "ACCNTS(P)") > 0 And Right(f.Name, 4) = ".xls" Or InStr(f.Name, "ACCNTS(P)") > 0 And Right(f.Name, 4) = ".xlsm" Then
        NR = NR + 1
        Sheets("file names").Range("A" & NR).Value = f.Name
        Sheets("file names").Range("B" & NR).Value = f.DateCreated
        On Error Resume Next
        Sheets("file names").Range("C" & NR).Value = f.DateLastModified
        On Error GoTo 0
    End If
Next f

End Sub


Your assistance is most appreciated
 
Last edited:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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